Apply strictNullChecks
to src/utils/*!exportUtils
(#10455
* Apply `strictNullChecks` to `src/utils/exportUtils` * strict fix * fix strictNullChecks issues in some utils * fix error message * test coverage * lint * more strictNullChecks * small optimisation for getUniqueRoomsWithIndividuals * tidy * test coverage
This commit is contained in:
parent
4ed6e39067
commit
81a4498a8f
18 changed files with 143 additions and 81 deletions
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
|
||||
import { mocked, Mocked } from "jest-mock";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { ClientEvent, EventType, IContent, MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { ClientEvent, EventType, IContent, MatrixClient, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import DMRoomMap from "../../src/utils/DMRoomMap";
|
||||
import { mkEvent, stubClient } from "../test-utils";
|
||||
|
@ -137,4 +137,56 @@ describe("DMRoomMap", () => {
|
|||
expect(dmRoomMap.getRoomIds()).toEqual(new Set([roomId1, roomId2, roomId4]));
|
||||
});
|
||||
});
|
||||
|
||||
describe("getUniqueRoomsWithIndividuals()", () => {
|
||||
const bigRoom = {
|
||||
roomId: "!bigRoom:server.org",
|
||||
getInvitedAndJoinedMemberCount: jest.fn().mockReturnValue(5000),
|
||||
} as unknown as Room;
|
||||
const dmWithBob = {
|
||||
roomId: "!dmWithBob:server.org",
|
||||
getInvitedAndJoinedMemberCount: jest.fn().mockReturnValue(2),
|
||||
} as unknown as Room;
|
||||
const dmWithCharlie = {
|
||||
roomId: "!dmWithCharlie:server.org",
|
||||
getInvitedAndJoinedMemberCount: jest.fn().mockReturnValue(2),
|
||||
} as unknown as Room;
|
||||
const smallRoom = {
|
||||
roomId: "!smallRoom:server.org",
|
||||
getInvitedAndJoinedMemberCount: jest.fn().mockReturnValue(3),
|
||||
} as unknown as Room;
|
||||
|
||||
const mDirectContent = {
|
||||
"@bob:server.org": [bigRoom.roomId, dmWithBob.roomId, smallRoom.roomId],
|
||||
"@charlie:server.org": [dmWithCharlie.roomId, smallRoom.roomId],
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
client.getAccountData.mockReturnValue(mkMDirectEvent(mDirectContent));
|
||||
client.getRoom.mockImplementation((roomId: string) =>
|
||||
[bigRoom, smallRoom, dmWithCharlie, dmWithBob].find((room) => room.roomId === roomId),
|
||||
);
|
||||
});
|
||||
|
||||
it("returns an empty object when room map has not been populated", () => {
|
||||
const instance = new DMRoomMap(client);
|
||||
expect(instance.getUniqueRoomsWithIndividuals()).toEqual({});
|
||||
});
|
||||
|
||||
it("returns map of users to rooms with 2 members", () => {
|
||||
const dmRoomMap = new DMRoomMap(client);
|
||||
dmRoomMap.start();
|
||||
expect(dmRoomMap.getUniqueRoomsWithIndividuals()).toEqual({
|
||||
"@bob:server.org": dmWithBob,
|
||||
"@charlie:server.org": dmWithCharlie,
|
||||
});
|
||||
});
|
||||
|
||||
it("excludes rooms that are not found by matrixClient", () => {
|
||||
client.getRoom.mockReset().mockReturnValue(undefined);
|
||||
const dmRoomMap = new DMRoomMap(client);
|
||||
dmRoomMap.start();
|
||||
expect(dmRoomMap.getUniqueRoomsWithIndividuals()).toEqual({});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue