|
| 1 | +package csapi_tests |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/tidwall/gjson" |
| 7 | + |
| 8 | + "github.com/matrix-org/complement/internal/b" |
| 9 | + "github.com/matrix-org/complement/internal/client" |
| 10 | + "github.com/matrix-org/complement/internal/match" |
| 11 | + "github.com/matrix-org/complement/internal/must" |
| 12 | +) |
| 13 | + |
| 14 | +func TestRoomAlias(t *testing.T) { |
| 15 | + deployment := Deploy(t, b.BlueprintAlice) |
| 16 | + defer deployment.Destroy(t) |
| 17 | + authedClient := deployment.Client(t, "hs1", "@alice:hs1") |
| 18 | + t.Run("Parallel", func(t *testing.T) { |
| 19 | + // sytest: PUT /directory/room/:room_alias creates alias |
| 20 | + t.Run("PUT /directory/room/:room_alias creates alias", func(t *testing.T) { |
| 21 | + t.Parallel() |
| 22 | + roomID := authedClient.CreateRoom(t, map[string]interface{}{ |
| 23 | + "visibility": "public", |
| 24 | + "preset": "public_chat", |
| 25 | + }) |
| 26 | + |
| 27 | + roomAlias := "#room_alias_test:hs1" |
| 28 | + |
| 29 | + reqBody := client.WithJSONBody(t, map[string]interface{}{ |
| 30 | + "room_id": roomID, |
| 31 | + }) |
| 32 | + |
| 33 | + _ = authedClient.MustDoFunc(t, "PUT", []string{"_matrix", "client", "r0", "directory", "room", roomAlias}, reqBody) |
| 34 | + |
| 35 | + res := authedClient.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "directory", "room", roomAlias}) |
| 36 | + |
| 37 | + must.MatchResponse(t, res, match.HTTPResponse{ |
| 38 | + JSON: []match.JSON{ |
| 39 | + match.JSONKeyPresent("room_id"), |
| 40 | + match.JSONKeyTypeEqual("room_id", gjson.String), |
| 41 | + match.JSONKeyEqual("room_id", roomID), |
| 42 | + }, |
| 43 | + }) |
| 44 | + }) |
| 45 | + // sytest: GET /rooms/:room_id/aliases lists aliases |
| 46 | + t.Run("GET /rooms/:room_id/aliases lists aliases", func(t *testing.T) { |
| 47 | + t.Parallel() |
| 48 | + roomID := authedClient.CreateRoom(t, map[string]interface{}{ |
| 49 | + "visibility": "public", |
| 50 | + "preset": "public_chat", |
| 51 | + }) |
| 52 | + |
| 53 | + res := authedClient.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "aliases"}) |
| 54 | + |
| 55 | + must.MatchResponse(t, res, match.HTTPResponse{ |
| 56 | + JSON: []match.JSON{ |
| 57 | + match.JSONKeyPresent("aliases"), |
| 58 | + match.JSONKeyEqual("aliases", []interface{}{}), |
| 59 | + }, |
| 60 | + }) |
| 61 | + |
| 62 | + roomAlias := "#room_alias:hs1" |
| 63 | + |
| 64 | + reqBody := client.WithJSONBody(t, map[string]interface{}{ |
| 65 | + "room_id": roomID, |
| 66 | + }) |
| 67 | + |
| 68 | + _ = authedClient.MustDoFunc(t, "PUT", []string{"_matrix", "client", "r0", "directory", "room", roomAlias}, reqBody) |
| 69 | + |
| 70 | + res = authedClient.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "aliases"}) |
| 71 | + |
| 72 | + must.MatchResponse(t, res, match.HTTPResponse{ |
| 73 | + JSON: []match.JSON{ |
| 74 | + match.JSONKeyPresent("aliases"), |
| 75 | + match.JSONKeyEqual("aliases", []interface{}{roomAlias}), |
| 76 | + }, |
| 77 | + }) |
| 78 | + }) |
| 79 | + }) |
| 80 | +} |
0 commit comments