1package tinyclient23import (4 "context"5 "encoding/json"6 "net/http"7 "net/http/httptest"8 "strings"9 "testing"1011 "github.com/FelineStateMachine/tinyrelay/internal/policy"12)1314type typedRoomsBackend struct{ fakeBackend }1516func (typedRoomsBackend) Query(context.Context, string, []json.RawMessage, string) (any, error) {17 panic("typed room reads must not use Backend.Query")18}1920func (typedRoomsBackend) ListRooms(context.Context, string, string, int) (RoomList, error) {21 return RoomList{Rooms: []RoomSummary{{ID: "build", Name: "Build", Access: "open"}}}, nil22}2324func (typedRoomsBackend) ReadRoom(context.Context, string, string, string, int) (RoomPage, error) {25 return RoomPage{Room: RoomSummary{ID: "build", Name: "Build"}}, nil26}2728func (typedRoomsBackend) ReadThread(context.Context, string, string, string, string, int) (RoomPage, error) {29 return RoomPage{Room: RoomSummary{ID: "build", Name: "Build"}}, nil30}3132func 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}