Skip to content

Commit efb0e04

Browse files
committed
Test for MSC4115 support
1 parent d73c81a commit efb0e04

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

tests/msc4115/main_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/matrix-org/complement"
7+
)
8+
9+
func TestMain(m *testing.M) {
10+
complement.TestMain(m, "msc4115")
11+
}

tests/msc4115/msc4115_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package tests
2+
3+
import (
4+
"github.com/matrix-org/complement/b"
5+
"github.com/matrix-org/complement/client"
6+
"github.com/matrix-org/complement/runtime"
7+
"testing"
8+
9+
"github.com/matrix-org/complement"
10+
"github.com/matrix-org/complement/helpers"
11+
)
12+
13+
// MSC4115: membership information on events
14+
//
15+
// Alice sends one message before bob joins, then one after. Bob reads both messages, and checks the membership state
16+
// on each.
17+
func TestMSC4115(t *testing.T) {
18+
runtime.SkipIf(t, runtime.Dendrite) // not yet implemented
19+
20+
deployment := complement.Deploy(t, 1)
21+
defer deployment.Destroy(t)
22+
23+
alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
24+
bob := deployment.Register(t, "hs1", helpers.RegistrationOpts{})
25+
26+
roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"})
27+
preJoinEventId := alice.SendEventSynced(t, roomID, b.Event{Type: "m.room.message",
28+
Content: map[string]interface{}{
29+
"msgtype": "m.text",
30+
"body": "prejoin",
31+
}})
32+
bob.MustJoinRoom(t, roomID, []string{"hs1"})
33+
postJoinEventId := alice.SendEventSynced(t, roomID, b.Event{Type: "m.room.message",
34+
Content: map[string]interface{}{
35+
"msgtype": "m.text",
36+
"body": "postjoin",
37+
}})
38+
39+
// Now Bob syncs, to get the messages
40+
syncResult, _ := bob.MustSync(t, client.SyncReq{})
41+
roomSyncResult := syncResult.Get("rooms.join." + client.GjsonEscape(roomID))
42+
43+
// ... and we check the membership value for each event
44+
checkEventMembership := func(eventID string, expectedMembership string) {
45+
for _, ev := range roomSyncResult.Get("timeline.events").Array() {
46+
if ev.Get("event_id").Str == eventID {
47+
// found the right event; check the MSC4115 value
48+
t.Logf("Event %s from timeline: %s", eventID, ev)
49+
membership := ev.Get("unsigned." + client.GjsonEscape("io.element.msc4115.membership")).Str
50+
if membership != expectedMembership {
51+
t.Errorf("Incorrect membership for event; got %s, want %s", membership, expectedMembership)
52+
}
53+
return
54+
}
55+
}
56+
t.Errorf("Did not find event %s in timeline", eventID)
57+
}
58+
59+
checkEventMembership(preJoinEventId, "leave")
60+
checkEventMembership(postJoinEventId, "join")
61+
}

0 commit comments

Comments
 (0)