More tests

This commit is contained in:
Kegan Dougal 2023-01-20 12:38:58 +00:00
parent 8e774e1924
commit 6a75054e1a
2 changed files with 40 additions and 5 deletions

View file

@ -322,11 +322,7 @@ export class SlidingSyncManager {
// gradually request more over time, even on errors.
await sleep(gapBetweenRequestsMs);
}
const listData = this.slidingSync.getListData(SlidingSyncManager.ListSearch);
if (!listData) {
// we failed to do the first request, keep trying
continue;
}
const listData = this.slidingSync.getListData(SlidingSyncManager.ListSearch)!;
hasMore = endIndex + 1 < listData.joinedCount;
startIndex += batchSize;
firstTime = false;

View file

@ -290,4 +290,43 @@ describe("SlidingRoomListStore", () => {
await p;
expect(store.orderedLists[tagId].map((r) => r.roomId)).toEqual([roomC, roomA, roomB].map((r) => r.roomId));
});
it("gracefully handles unknown room IDs", async () => {
await store.start();
const roomIdA = "!a:localhost";
const roomIdB = "!b:localhost"; // does not exist
const roomIdC = "!c:localhost";
const roomIndexToRoomId = {
0: roomIdA,
1: roomIdB, // does not exist
2: roomIdC,
};
const tagId = DefaultTagID.Favourite;
const joinCount = 10;
// seed the store with 2 rooms
const roomA = new Room(roomIdA, context.client!, context.client!.getUserId());
const roomC = new Room(roomIdC, context.client!, context.client!.getUserId());
mocked(context.client!.getRoom).mockImplementation((roomId: string) => {
switch (roomId) {
case roomIdA:
return roomA;
case roomIdC:
return roomC;
}
return null;
});
mocked(context._SlidingSyncManager!.slidingSync.getListData).mockImplementation((key: string) => {
if (key !== tagId) {
return null;
}
return {
roomIndexToRoomId: roomIndexToRoomId,
joinedCount: joinCount,
};
});
let p = untilEmission(store, LISTS_UPDATE_EVENT);
context.slidingSyncManager.slidingSync.emit(SlidingSyncEvent.List, tagId, joinCount, roomIndexToRoomId);
await p;
expect(store.orderedLists[tagId]).toEqual([roomA, roomC]);
});
});