From f2dd0d907925ba9e75203e9cbc223c98d2323cf3 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 22 Apr 2024 20:35:33 +0100 Subject: [PATCH] Test for MSC4115 support --- tests/msc4115/main_test.go | 11 ++++++ tests/msc4115/msc4115_test.go | 64 +++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 tests/msc4115/main_test.go create mode 100644 tests/msc4115/msc4115_test.go diff --git a/tests/msc4115/main_test.go b/tests/msc4115/main_test.go new file mode 100644 index 00000000..edb9d0f0 --- /dev/null +++ b/tests/msc4115/main_test.go @@ -0,0 +1,11 @@ +package tests + +import ( + "testing" + + "github.com/matrix-org/complement" +) + +func TestMain(m *testing.M) { + complement.TestMain(m, "msc4115") +} diff --git a/tests/msc4115/msc4115_test.go b/tests/msc4115/msc4115_test.go new file mode 100644 index 00000000..4f5bb852 --- /dev/null +++ b/tests/msc4115/msc4115_test.go @@ -0,0 +1,64 @@ +package tests + +import ( + "github.com/matrix-org/complement/b" + "github.com/matrix-org/complement/client" + "github.com/matrix-org/complement/runtime" + "testing" + + "github.com/matrix-org/complement" + "github.com/matrix-org/complement/helpers" +) + +// MSC4115: membership information on events +// +// Alice sends one message before bob joins, then one after. Bob reads both messages, and checks the membership state +// on each. +func TestMSC4115(t *testing.T) { + runtime.SkipIf(t, runtime.Dendrite) // not yet implemented + + deployment := complement.Deploy(t, 1) + defer deployment.Destroy(t) + + alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) + bob := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) + + roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) + preJoinEventID := alice.SendEventSynced(t, roomID, b.Event{Type: "m.room.message", + Content: map[string]interface{}{ + "msgtype": "m.text", + "body": "prejoin", + }}) + bob.MustJoinRoom(t, roomID, []string{"hs1"}) + postJoinEventID := alice.SendEventSynced(t, roomID, b.Event{Type: "m.room.message", + Content: map[string]interface{}{ + "msgtype": "m.text", + "body": "postjoin", + }}) + + // Now Bob syncs, to get the messages + syncResult, _ := bob.MustSync(t, client.SyncReq{}) + if err := client.SyncTimelineHasEventID(roomID, preJoinEventID)(alice.UserID, syncResult); err != nil { + t.Fatalf("Sync response lacks prejoin event: %s", err) + } + if err := client.SyncTimelineHasEventID(roomID, postJoinEventID)(alice.UserID, syncResult); err != nil { + t.Fatalf("Sync response lacks prejoin event: %s", err) + } + + // ... and we check the membership value for each event. Should be "leave" for each event until the join. + haveSeenJoin := false + roomSyncResult := syncResult.Get("rooms.join." + client.GjsonEscape(roomID)) + for _, ev := range roomSyncResult.Get("timeline.events").Array() { + if ev.Get("type").Str == "m.room.member" && ev.Get("state_key").Str == bob.UserID { + haveSeenJoin = true + } + membership := ev.Get("unsigned." + client.GjsonEscape("io.element.msc4115.membership")).Str + expectedMembership := "leave" + if haveSeenJoin { + expectedMembership = "join" + } + if membership != expectedMembership { + t.Errorf("Incorrect membership for event %s; got %s, want %s", ev, membership, expectedMembership) + } + } +}