tinyrelayfile
tinyrelay/tinyclient/read_contracts_test.go/

tinyclient/read_contracts_test.go raw
1package tinyclient
2
3import (
4 "context"
5 "encoding/json"
6 "net/http"
7 "net/http/httptest"
8 "strings"
9 "testing"
10
11 "github.com/FelineStateMachine/tinyrelay/internal/policy"
12)
13
14type typedRoomsBackend struct{ fakeBackend }
15
16func (typedRoomsBackend) Query(context.Context, string, []json.RawMessage, string) (any, error) {
17 panic("typed room reads must not use Backend.Query")
18}
19
20func (typedRoomsBackend) ListRooms(context.Context, string, string, int) (RoomList, error) {
21 return RoomList{Rooms: []RoomSummary{{ID: "build", Name: "Build", Access: "open"}}}, nil
22}
23
24func (typedRoomsBackend) ReadRoom(context.Context, string, string, string, int) (RoomPage, error) {
25 return RoomPage{Room: RoomSummary{ID: "build", Name: "Build"}}, nil
26}
27
28func (typedRoomsBackend) ReadThread(context.Context, string, string, string, string, int) (RoomPage, error) {
29 return RoomPage{Room: RoomSummary{ID: "build", Name: "Build"}}, nil
30}
31
32func TestTypedRoomsReaderAvoidsLegacyQuery(t *testing.T) {
33 backend := typedRoomsBackend{fakeBackend: fakeBackend{policy: policy.Defaults(strings.Repeat("a", 64))}}
34 app, err := New(&backend, Options{})
35 if err != nil {
36 t.Fatal(err)
37 }
38 for _, path := range []string{"/rooms/build"} {
39 response := httptest.NewRecorder()
40 app.ServeHTTP(response, httptest.NewRequest(http.MethodGet, path, nil))
41 if response.Code != http.StatusOK {
42 t.Fatalf("%s: status %d", path, response.Code)
43 }
44 if !strings.Contains(response.Body.String(), "Build") {
45 t.Fatalf("%s: typed room result missing from page", path)
46 }
47 }
48}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs