Skip to content

Commit 5c243d9

Browse files
add 30rooms/22profile tests (#511)
1 parent 172daf5 commit 5c243d9

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

internal/client/client.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -741,29 +741,41 @@ func SyncInvitedTo(userID, roomID string) SyncCheckOpt {
741741
}
742742
}
743743

744-
// Check that `userID` gets joined to `roomID` by inspecting the join timeline for a membership event
745-
func SyncJoinedTo(userID, roomID string) SyncCheckOpt {
744+
// Check that `userID` gets joined to `roomID` by inspecting the join timeline for a membership event.
745+
//
746+
// Additional checks can be passed to narrow down the check, all must pass.
747+
func SyncJoinedTo(userID, roomID string, checks ...func(gjson.Result) bool) SyncCheckOpt {
746748
checkJoined := func(ev gjson.Result) bool {
747-
return ev.Get("type").Str == "m.room.member" && ev.Get("state_key").Str == userID && ev.Get("content.membership").Str == "join"
749+
if ev.Get("type").Str == "m.room.member" && ev.Get("state_key").Str == userID && ev.Get("content.membership").Str == "join" {
750+
for _, check := range checks {
751+
if !check(ev) {
752+
// short-circuit, bail early
753+
return false
754+
}
755+
}
756+
// passed both basic join check and all other checks
757+
return true
758+
}
759+
return false
748760
}
749761
return func(clientUserID string, topLevelSyncJSON gjson.Result) error {
750762
// Check both the timeline and the state events for the join event
751763
// since on initial sync, the state events may only be in
752764
// <room>.state.events.
753-
err := loopArray(
765+
firstErr := loopArray(
754766
topLevelSyncJSON, "rooms.join."+GjsonEscape(roomID)+".timeline.events", checkJoined,
755767
)
756-
if err == nil {
768+
if firstErr == nil {
757769
return nil
758770
}
759771

760-
err = loopArray(
772+
secondErr := loopArray(
761773
topLevelSyncJSON, "rooms.join."+GjsonEscape(roomID)+".state.events", checkJoined,
762774
)
763-
if err == nil {
775+
if secondErr == nil {
764776
return nil
765777
}
766-
return fmt.Errorf("SyncJoinedTo(%s): %s", roomID, err)
778+
return fmt.Errorf("SyncJoinedTo(%s): %s & %s", roomID, firstErr, secondErr)
767779
}
768780
}
769781

tests/csapi/room_profile_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package csapi_tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/tidwall/gjson"
7+
8+
"github.com/matrix-org/complement/internal/b"
9+
"github.com/matrix-org/complement/internal/client"
10+
)
11+
12+
func TestAvatarUrlUpdate(t *testing.T) {
13+
testProfileFieldUpdate(t, "avatar_url")
14+
}
15+
16+
func TestDisplayNameUpdate(t *testing.T) {
17+
testProfileFieldUpdate(t, "displayname")
18+
}
19+
20+
// sytest: $datum updates affect room member events
21+
func testProfileFieldUpdate(t *testing.T, field string) {
22+
deployment := Deploy(t, b.BlueprintAlice)
23+
defer deployment.Destroy(t)
24+
25+
const bogusData = "LemurLover"
26+
27+
alice := deployment.Client(t, "hs1", "@alice:hs1")
28+
29+
roomID := alice.CreateRoom(t, map[string]interface{}{
30+
"preset": "public_chat",
31+
})
32+
33+
sinceToken := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID))
34+
35+
alice.MustDoFunc(
36+
t,
37+
"PUT",
38+
[]string{"_matrix", "client", "v3", "profile", alice.UserID, field},
39+
client.WithJSONBody(t, map[string]interface{}{
40+
field: bogusData,
41+
}),
42+
)
43+
44+
alice.MustSyncUntil(t, client.SyncReq{Since: sinceToken}, client.SyncJoinedTo(alice.UserID, roomID, func(result gjson.Result) bool {
45+
return result.Get("content."+field).Str == bogusData
46+
}))
47+
}

0 commit comments

Comments
 (0)