Created
January 25, 2023 12:20
-
-
Save DMRobertson/337a930e3e7d76feb8f66d091b3d2314 to your computer and use it in GitHub Desktop.
Complement test for join-leave-join sync response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package csapi_tests | |
import ( | |
"github.com/matrix-org/complement/internal/b" | |
"github.com/matrix-org/complement/internal/client" | |
"testing" | |
) | |
func TestRejoinBehaviour(t *testing.T) { | |
deployment := Deploy(t, b.BlueprintFederationOneToOneRoom) | |
defer deployment.Destroy(t) | |
alice := deployment.Client(t, "hs1", "@alice:hs1") | |
bob := deployment.Client(t, "hs2", "@bob:hs2") | |
t.Log("Alice creates a public room") | |
roomID := alice.CreateRoom(t, map[string]interface{}{ | |
"preset": "public_chat", | |
}) | |
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) | |
t.Log("Bob joins that room") | |
bob.JoinRoom(t, roomID, []string{"hs1"}) | |
bobNextBatch := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) | |
t.Log("Alice sends a message in the room") | |
aliceMessageID1 := alice.SendEventSynced(t, roomID, b.Event{ | |
Type: "m.room.message", | |
Content: map[string]interface{}{ | |
"msgtype": "m.text", | |
"body": "Hello world!", | |
}, | |
}) | |
t.Log("Bob syncs until he sees that message") | |
bobNextBatch = bob.MustSyncUntil(t, client.SyncReq{Since: bobNextBatch}, client.SyncTimelineHasEventID(roomID, aliceMessageID1)) | |
t.Log("Bob leaves the room") | |
bob.LeaveRoom(t, roomID) | |
bobNextBatch = bob.MustSyncUntil( | |
t, | |
client.SyncReq{Since: bobNextBatch}, | |
client.SyncLeftFrom(bob.UserID, roomID), | |
) | |
t.Log("Alice sends a second message in that room") | |
alice.SendEventSynced(t, roomID, b.Event{ | |
Type: "m.room.message", | |
Content: map[string]interface{}{ | |
"msgtype": "m.text", | |
"body": "Hello again world!", | |
}, | |
}) | |
t.Log("Bob rejoins and waits to see his join") | |
bob.JoinRoom(t, roomID, []string{"hs1"}) | |
bob.MustSyncUntil(t, client.SyncReq{Since: bobNextBatch}, client.SyncJoinedTo(bob.UserID, roomID)) | |
t.Log("Bob's sync response should include his join, not Alice's second message") | |
// Repeat the sync so we can inspect its outcome | |
response, _ := bob.MustSync(t, client.SyncReq{Since: bobNextBatch}) | |
t.Logf("Got response: %s", response.Raw) | |
roomResponse := response.Get("rooms.join." + roomID + ".timeline.events") | |
if len(roomResponse.Array()) != 1 { | |
t.Fatalf("Expected 1 event in room, got %d", len(roomResponse.Array())) | |
} | |
event := roomResponse.Array()[0] | |
if event.Get("type").Str != "m.room.member" || event.Get("sender").Str != bob.UserID || event.Get("content.membership").Str != "join" { | |
t.Errorf("Couldn't find join event for bob") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment