sliding-sync/tests-e2e/unread_count_test.go

61 lines
1.5 KiB
Go
Raw Normal View History

package syncv3_test
import (
"fmt"
"testing"
2023-10-11 12:23:46 +01:00
"github.com/matrix-org/complement/b"
"github.com/matrix-org/complement/client"
"github.com/matrix-org/sliding-sync/sync3"
"github.com/matrix-org/sliding-sync/testutils/m"
)
func TestUnreadCountsUpdate(t *testing.T) {
alice := registerNewUser(t)
bob := registerNewUser(t)
2023-10-11 12:23:46 +01:00
roomID := alice.MustCreateRoom(t, map[string]interface{}{
"preset": "public_chat",
})
bob.JoinRoom(t, roomID, nil)
2023-10-11 12:23:46 +01:00
eventID := bob.SendEventSynced(t, roomID, b.Event{
Type: "m.room.message",
Content: map[string]interface{}{
"msgtype": "m.text",
"body": "Hello World",
},
})
res := alice.SlidingSync(t, sync3.Request{
2023-01-18 15:31:44 +00:00
Lists: map[string]sync3.RequestList{
"a": {
Ranges: sync3.SliceRanges{{0, 20}},
},
},
})
m.MatchResponse(t, res, m.MatchRoomSubscriptionsStrict(map[string][]m.RoomMatcher{
roomID: {
m.MatchRoomNotificationCount(1),
},
}))
2023-10-11 12:23:46 +01:00
alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "read_markers"}, client.WithJSONBody(t, map[string]interface{}{
"m.fully_read": eventID,
"m.read": eventID,
}))
alice.SlidingSyncUntil(t, res.Pos, sync3.Request{
2023-01-18 15:31:44 +00:00
Lists: map[string]sync3.RequestList{
"a": {
Ranges: sync3.SliceRanges{{0, 20}},
},
},
}, func(r *sync3.Response) error {
room, ok := r.Rooms[roomID]
if !ok {
return fmt.Errorf("no room %s", roomID)
}
if room.NotificationCount != 0 {
return fmt.Errorf("notif count = %d", room.NotificationCount)
}
return nil
})
}