Skip to content

Commit 6e900e0

Browse files
authored
Add test for leaves in forgotten rooms appearing in incremental /sync (#620)
Signed-off-by: Sean Quah <[email protected]>
1 parent 8e90476 commit 6e900e0

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

tests/csapi/apidoc_room_forget_test.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestRoomForget(t *testing.T) {
5757
})
5858
})
5959
// sytest: Forgetting room does not show up in v2 /sync
60-
t.Run("Forgetting room does not show up in v2 /sync", func(t *testing.T) {
60+
t.Run("Forgetting room does not show up in v2 initial /sync", func(t *testing.T) {
6161
t.Parallel()
6262
roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"})
6363
bob.JoinRoom(t, roomID, []string{})
@@ -98,6 +98,47 @@ func TestRoomForget(t *testing.T) {
9898
t.Errorf("Did not expect room %s in left", roomID)
9999
}
100100
})
101+
t.Run("Leave for forgotten room shows up in v2 incremental /sync", func(t *testing.T) {
102+
// Note that this test runs counter to the wording of the spec. At the time of writing,
103+
// the spec says that forgotten rooms should not show up in any /sync responses, but
104+
// that would make it impossible for other devices to determine that a room has been
105+
// left if it is forgotten quickly. This is arguably a bug in the spec.
106+
t.Parallel()
107+
roomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"})
108+
bob.JoinRoom(t, roomID, []string{})
109+
alice.SendEventSynced(t, roomID, b.Event{
110+
Type: "m.room.message",
111+
Content: map[string]interface{}{
112+
"msgtype": "m.text",
113+
"body": "Hello world!",
114+
},
115+
})
116+
tokenBeforeLeave := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID))
117+
alice.LeaveRoom(t, roomID)
118+
// Ensure Alice left the room
119+
bob.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(alice.UserID, roomID))
120+
alice.MustDoFunc(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "forget"})
121+
bob.SendEventSynced(t, roomID, b.Event{
122+
Type: "m.room.message",
123+
Content: map[string]interface{}{
124+
"msgtype": "m.text",
125+
"body": "Hello world!",
126+
},
127+
})
128+
// The leave for the room is expected to show up in the next incremental /sync.
129+
includeLeaveFilter, _ := json.Marshal(map[string]interface{}{
130+
"room": map[string]interface{}{
131+
"include_leave": true,
132+
},
133+
})
134+
result, _ := alice.MustSync(t, client.SyncReq{
135+
Since: tokenBeforeLeave,
136+
Filter: string(includeLeaveFilter),
137+
})
138+
if !result.Get("rooms.leave." + client.GjsonEscape(roomID)).Exists() {
139+
t.Errorf("Did not see room %s in left", roomID)
140+
}
141+
})
101142
// sytest: Can forget room you've been kicked from
102143
t.Run("Can forget room you've been kicked from", func(t *testing.T) {
103144
t.Parallel()

0 commit comments

Comments
 (0)