|
| 1 | +package tests |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/url" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/tidwall/gjson" |
| 8 | + |
| 9 | + "github.com/matrix-org/complement/internal/b" |
| 10 | + "github.com/matrix-org/complement/internal/client" |
| 11 | + "github.com/matrix-org/complement/internal/match" |
| 12 | + "github.com/matrix-org/complement/internal/must" |
| 13 | +) |
| 14 | + |
| 15 | +func TestRoomState(t *testing.T) { |
| 16 | + deployment := Deploy(t, b.BlueprintAlice) |
| 17 | + defer deployment.Destroy(t) |
| 18 | + authedClient := deployment.Client(t, "hs1", "@alice:hs1") |
| 19 | + t.Run("Parallel", func(t *testing.T) { |
| 20 | + // sytest: GET /rooms/:room_id/state/m.room.member/:user_id fetches my membership |
| 21 | + t.Run("GET /rooms/:room_id/state/m.room.member/:user_id fetches my membership", func(t *testing.T) { |
| 22 | + t.Parallel() |
| 23 | + roomID := authedClient.CreateRoom(t, map[string]interface{}{ |
| 24 | + "visibility": "public", |
| 25 | + "preset": "public_chat", |
| 26 | + }) |
| 27 | + res := authedClient.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "state", "m.room.member", authedClient.UserID}) |
| 28 | + must.MatchResponse(t, res, match.HTTPResponse{ |
| 29 | + JSON: []match.JSON{ |
| 30 | + match.JSONKeyPresent("membership"), |
| 31 | + match.JSONKeyTypeEqual("membership", gjson.String), |
| 32 | + match.JSONKeyEqual("membership", "join"), |
| 33 | + }, |
| 34 | + }) |
| 35 | + }) |
| 36 | + // sytest: GET /rooms/:room_id/state/m.room.member/:user_id?format=event fetches my membership event |
| 37 | + t.Run("GET /rooms/:room_id/state/m.room.member/:user_id?format=event fetches my membership event", func(t *testing.T) { |
| 38 | + t.Parallel() |
| 39 | + queryParams := url.Values{} |
| 40 | + queryParams.Set("format", "event") |
| 41 | + roomID := authedClient.CreateRoom(t, map[string]interface{}{ |
| 42 | + "visibility": "public", |
| 43 | + "preset": "public_chat", |
| 44 | + }) |
| 45 | + res := authedClient.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "state", "m.room.member", authedClient.UserID}, client.WithQueries(queryParams)) |
| 46 | + must.MatchResponse(t, res, match.HTTPResponse{ |
| 47 | + JSON: []match.JSON{ |
| 48 | + match.JSONKeyPresent("sender"), |
| 49 | + match.JSONKeyPresent("room_id"), |
| 50 | + match.JSONKeyPresent("content"), |
| 51 | + match.JSONKeyEqual("sender", authedClient.UserID), |
| 52 | + match.JSONKeyEqual("room_id", roomID), |
| 53 | + match.JSONKeyEqual("content.membership", "join"), |
| 54 | + }, |
| 55 | + }) |
| 56 | + }) |
| 57 | + // sytest: GET /rooms/:room_id/state/m.room.power_levels fetches powerlevels |
| 58 | + t.Run("GET /rooms/:room_id/state/m.room.power_levels fetches powerlevels", func(t *testing.T) { |
| 59 | + t.Parallel() |
| 60 | + roomID := authedClient.CreateRoom(t, map[string]interface{}{ |
| 61 | + "visibility": "public", |
| 62 | + "preset": "public_chat", |
| 63 | + "room_alias_name": "room_alias", |
| 64 | + }) |
| 65 | + res := authedClient.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "state", "m.room.power_levels"}) |
| 66 | + must.MatchResponse(t, res, match.HTTPResponse{ |
| 67 | + JSON: []match.JSON{ |
| 68 | + match.JSONKeyPresent("ban"), |
| 69 | + match.JSONKeyPresent("kick"), |
| 70 | + match.JSONKeyPresent("redact"), |
| 71 | + match.JSONKeyPresent("users_default"), |
| 72 | + match.JSONKeyPresent("state_default"), |
| 73 | + match.JSONKeyPresent("events_default"), |
| 74 | + match.JSONKeyPresent("users"), |
| 75 | + match.JSONKeyPresent("events"), |
| 76 | + }, |
| 77 | + }) |
| 78 | + }) |
| 79 | + }) |
| 80 | +} |
0 commit comments