Skip to content

Commit 34c9561

Browse files
Add test for SYN-442 (#244)
* SYN-442 * fix synapse test failure and adds SyncUntilJoined * fix some oversights
1 parent 1301558 commit 34c9561

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

internal/client/client.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ func (c *CSAPI) SyncUntilInvitedTo(t *testing.T, roomID string) {
151151
c.SyncUntil(t, "", "", "rooms.invite."+GjsonEscape(roomID)+".invite_state.events", check)
152152
}
153153

154+
// SyncUntilJoined is a wrapper around SyncUntil.
155+
// It blocks and continually calls `/sync` until we've joined the given room.
156+
// Will time out after CSAPI.SyncUntilTimeout.
157+
func (c *CSAPI) SyncUntilJoined(t *testing.T, roomID string) {
158+
t.Helper()
159+
c.SyncUntilTimelineHas(t, roomID, func(event gjson.Result) bool {
160+
return event.Get("type").Str == "m.room.member" &&
161+
event.Get("content.membership").Str == "join" &&
162+
event.Get("state_key").Str == c.UserID
163+
})
164+
}
165+
154166
// SyncUntil blocks and continually calls /sync until
155167
// - the response contains a particular `key`, and
156168
// - its corresponding value is an array

tests/csapi/apidoc_room_members_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,55 @@ func TestRoomMembers(t *testing.T) {
107107
},
108108
)
109109
})
110+
// sytest: Test that we can be reinvited to a room we created
111+
t.Run("Test that we can be reinvited to a room we created", func(t *testing.T) {
112+
t.Parallel()
113+
roomID := alice.CreateRoom(t, map[string]interface{}{
114+
"preset": "private_chat",
115+
})
116+
117+
alice.InviteRoom(t, roomID, bob.UserID)
118+
119+
bob.SyncUntilInvitedTo(t, roomID)
120+
121+
bob.JoinRoom(t, roomID, nil)
122+
123+
// Sync to make sure bob has joined
124+
bob.SyncUntilJoined(t, roomID)
125+
126+
stateKey := ""
127+
alice.SendEventSynced(t, roomID, b.Event{
128+
Type: "m.room.power_levels",
129+
StateKey: &stateKey,
130+
Content: map[string]interface{}{
131+
"invite": 100,
132+
"users": map[string]interface{}{
133+
alice.UserID: 100,
134+
bob.UserID: 100,
135+
},
136+
},
137+
})
138+
139+
alice.LeaveRoom(t, roomID)
140+
141+
// Wait until alice has left the room
142+
bob.SyncUntilTimelineHas(
143+
t,
144+
roomID,
145+
func(ev gjson.Result) bool {
146+
return ev.Get("type").Str == "m.room.member" &&
147+
ev.Get("content.membership").Str == "leave" &&
148+
ev.Get("state_key").Str == alice.UserID
149+
},
150+
)
151+
152+
bob.InviteRoom(t, roomID, alice.UserID)
153+
154+
alice.SyncUntilInvitedTo(t, roomID)
155+
156+
alice.JoinRoom(t, roomID, nil)
157+
158+
alice.SyncUntilJoined(t, roomID)
159+
})
110160
})
111161
}

0 commit comments

Comments
 (0)