Use SlidingSyncUntilMembership for subscription test

This commit is contained in:
Till Faelligen 2023-09-19 14:43:41 +02:00
parent e8c4dc4b8c
commit d5f96eba7a
No known key found for this signature in database
GPG Key ID: ACCDC9606D472758

View File

@ -5,10 +5,9 @@ import (
"testing"
"time"
"github.com/tidwall/gjson"
"github.com/matrix-org/sliding-sync/sync3"
"github.com/matrix-org/sliding-sync/testutils/m"
"github.com/tidwall/gjson"
)
func TestRoomStateTransitions(t *testing.T) {
@ -627,32 +626,7 @@ func TestHeroesOnMembershipChanges(t *testing.T) {
subRoomID := alice.CreateRoom(t, map[string]interface{}{"preset": "public_chat"})
bob.JoinRoom(t, subRoomID, []string{})
res := alice.SlidingSyncUntil(t, "", sync3.Request{
RoomSubscriptions: map[string]sync3.RoomSubscription{
subRoomID: {
TimelineLimit: 10,
Heroes: &boolTrue,
},
},
}, func(response *sync3.Response) error {
r, ok := response.Rooms[subRoomID]
if !ok {
return fmt.Errorf("room %q not in response", subRoomID)
}
// wait for bob to be joined
for _, ev := range r.Timeline {
if gjson.GetBytes(ev, "type").Str != "m.room.member" {
continue
}
if gjson.GetBytes(ev, "state_key").Str != bob.UserID {
continue
}
if gjson.GetBytes(ev, "content.membership").Str == "join" {
return nil
}
}
return fmt.Errorf("%s is not joined to room %q", bob.UserID, subRoomID)
})
res := alice.SlidingSyncUntilMembership(t, "", subRoomID, bob, "join")
if c := len(res.Rooms[subRoomID].Heroes); c > 1 {
t.Errorf("expected 1 room hero, got %d", c)
}