Skip to content

Commit 97f6fe8

Browse files
add 30rooms/52members (#506)
1 parent 832bc69 commit 97f6fe8

File tree

1 file changed

+197
-0
lines changed

1 file changed

+197
-0
lines changed

tests/csapi/room_members_test.go

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
package csapi_tests
2+
3+
import (
4+
"net/url"
5+
"strings"
6+
"testing"
7+
8+
"github.com/tidwall/gjson"
9+
10+
"github.com/matrix-org/complement/internal/b"
11+
"github.com/matrix-org/complement/internal/client"
12+
"github.com/matrix-org/complement/internal/match"
13+
"github.com/matrix-org/complement/internal/must"
14+
"github.com/matrix-org/complement/runtime"
15+
)
16+
17+
// Maps every object by extracting `type` and `state_key` into a "$type|$state_key" string.
18+
func typeToStateKeyMapper(result gjson.Result) interface{} {
19+
return strings.Join([]string{result.Map()["type"].Str, result.Map()["state_key"].Str}, "|")
20+
}
21+
22+
// sytest: Can get rooms/{roomId}/members
23+
func TestGetRoomMembers(t *testing.T) {
24+
deployment := Deploy(t, b.BlueprintOneToOneRoom)
25+
defer deployment.Destroy(t)
26+
27+
alice := deployment.Client(t, "hs1", "@alice:hs1")
28+
bob := deployment.Client(t, "hs1", "@bob:hs1")
29+
30+
roomID := alice.CreateRoom(t, map[string]interface{}{
31+
"preset": "public_chat",
32+
})
33+
34+
bob.JoinRoom(t, roomID, nil)
35+
36+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID))
37+
38+
resp := alice.MustDoFunc(
39+
t,
40+
"GET",
41+
[]string{"_matrix", "client", "v3", "rooms", roomID, "members"},
42+
)
43+
44+
must.MatchResponse(t, resp, match.HTTPResponse{
45+
JSON: []match.JSON{
46+
match.JSONCheckOff("chunk",
47+
[]interface{}{
48+
"m.room.member|" + alice.UserID,
49+
"m.room.member|" + bob.UserID,
50+
}, typeToStateKeyMapper, nil),
51+
},
52+
StatusCode: 200,
53+
})
54+
}
55+
56+
// Utilize ?at= to get room members at a point in sync.
57+
// sytest: Can get rooms/{roomId}/members at a given point
58+
func TestGetRoomMembersAtPoint(t *testing.T) {
59+
runtime.SkipIf(t, runtime.Dendrite) // FIXME: https://github.com/matrix-org/dendrite/issues/1308
60+
61+
deployment := Deploy(t, b.BlueprintOneToOneRoom)
62+
defer deployment.Destroy(t)
63+
64+
alice := deployment.Client(t, "hs1", "@alice:hs1")
65+
bob := deployment.Client(t, "hs1", "@bob:hs1")
66+
67+
roomID := alice.CreateRoom(t, map[string]interface{}{
68+
"preset": "public_chat",
69+
})
70+
71+
alice.SendEventSynced(t, roomID, b.Event{
72+
Type: "m.room.message",
73+
Content: map[string]interface{}{
74+
"msgtype": "m.text",
75+
"body": "Hello world!",
76+
},
77+
})
78+
79+
_, since_token := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"})
80+
81+
bob.JoinRoom(t, roomID, nil)
82+
83+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID))
84+
85+
bob.SendEventSynced(t, roomID, b.Event{
86+
Type: "m.room.message",
87+
Content: map[string]interface{}{
88+
"msgtype": "m.text",
89+
"body": "Hello back",
90+
},
91+
})
92+
93+
resp := alice.MustDoFunc(
94+
t,
95+
"GET",
96+
[]string{"_matrix", "client", "v3", "rooms", roomID, "members"},
97+
client.WithQueries(url.Values{
98+
"at": []string{since_token},
99+
}),
100+
)
101+
102+
must.MatchResponse(t, resp, match.HTTPResponse{
103+
JSON: []match.JSON{
104+
match.JSONCheckOff("chunk",
105+
[]interface{}{
106+
"m.room.member|" + alice.UserID,
107+
}, typeToStateKeyMapper, nil),
108+
},
109+
StatusCode: 200,
110+
})
111+
}
112+
113+
// sytest: Can filter rooms/{roomId}/members
114+
func TestGetFilteredRoomMembers(t *testing.T) {
115+
runtime.SkipIf(t, runtime.Dendrite) // FIXME: https://github.com/matrix-org/dendrite/issues/1308
116+
117+
deployment := Deploy(t, b.BlueprintOneToOneRoom)
118+
defer deployment.Destroy(t)
119+
120+
alice := deployment.Client(t, "hs1", "@alice:hs1")
121+
bob := deployment.Client(t, "hs1", "@bob:hs1")
122+
123+
roomID := alice.CreateRoom(t, map[string]interface{}{
124+
"preset": "public_chat",
125+
})
126+
127+
bob.JoinRoom(t, roomID, nil)
128+
129+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID))
130+
131+
bob.LeaveRoom(t, roomID)
132+
133+
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID))
134+
135+
t.Run("not_membership", func(t *testing.T) {
136+
resp := alice.MustDoFunc(
137+
t,
138+
"GET",
139+
[]string{"_matrix", "client", "v3", "rooms", roomID, "members"},
140+
client.WithQueries(url.Values{
141+
"not_membership": []string{"leave"},
142+
}),
143+
)
144+
145+
must.MatchResponse(t, resp, match.HTTPResponse{
146+
JSON: []match.JSON{
147+
match.JSONCheckOff("chunk",
148+
[]interface{}{
149+
"m.room.member|" + alice.UserID,
150+
}, typeToStateKeyMapper, nil),
151+
},
152+
StatusCode: 200,
153+
})
154+
})
155+
156+
t.Run("membership/leave", func(t *testing.T) {
157+
resp := alice.MustDoFunc(
158+
t,
159+
"GET",
160+
[]string{"_matrix", "client", "v3", "rooms", roomID, "members"},
161+
client.WithQueries(url.Values{
162+
"membership": []string{"leave"},
163+
}),
164+
)
165+
166+
must.MatchResponse(t, resp, match.HTTPResponse{
167+
JSON: []match.JSON{
168+
match.JSONCheckOff("chunk",
169+
[]interface{}{
170+
"m.room.member|" + bob.UserID,
171+
}, typeToStateKeyMapper, nil),
172+
},
173+
StatusCode: 200,
174+
})
175+
})
176+
177+
t.Run("membership/join", func(t *testing.T) {
178+
resp := alice.MustDoFunc(
179+
t,
180+
"GET",
181+
[]string{"_matrix", "client", "v3", "rooms", roomID, "members"},
182+
client.WithQueries(url.Values{
183+
"membership": []string{"join"},
184+
}),
185+
)
186+
187+
must.MatchResponse(t, resp, match.HTTPResponse{
188+
JSON: []match.JSON{
189+
match.JSONCheckOff("chunk",
190+
[]interface{}{
191+
"m.room.member|" + alice.UserID,
192+
}, typeToStateKeyMapper, nil),
193+
},
194+
StatusCode: 200,
195+
})
196+
})
197+
}

0 commit comments

Comments
 (0)