Pass around MatrixClients instead of using MatrixClientPeg (#10984)

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
Michael Telatynski 2023-06-01 14:43:24 +01:00 committed by GitHub
parent b6b9ce3c46
commit 21ffc50f1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 152 additions and 135 deletions

View file

@ -59,8 +59,8 @@ const mockDispatcher = mocked(dis);
const flushPromises = async () => await new Promise(process.nextTick);
describe("DeviceListener", () => {
let mockClient: Mocked<MatrixClient> | undefined;
let mockCrypto: Mocked<CryptoApi> | undefined;
let mockClient: Mocked<MatrixClient>;
let mockCrypto: Mocked<CryptoApi>;
// spy on various toasts' hide and show functions
// easier than mocking
@ -111,7 +111,7 @@ describe("DeviceListener", () => {
const createAndStart = async (): Promise<DeviceListener> => {
const instance = new DeviceListener();
instance.start();
instance.start(mockClient);
await flushPromises();
return instance;
};

View file

@ -52,7 +52,7 @@ describe("setDMRoom", () => {
describe("when logged in as a guest and marking a room as DM", () => {
beforeEach(() => {
mocked(client.isGuest).mockReturnValue(true);
setDMRoom(roomId1, userId1);
setDMRoom(client, roomId1, userId1);
});
it("should not update the account data", () => {
@ -62,7 +62,7 @@ describe("setDMRoom", () => {
describe("when adding a new room to an existing DM relation", () => {
beforeEach(() => {
setDMRoom(roomId4, userId1);
setDMRoom(client, roomId4, userId1);
});
it("should update the account data accordingly", () => {
@ -75,7 +75,7 @@ describe("setDMRoom", () => {
describe("when adding a new DM room", () => {
beforeEach(() => {
setDMRoom(roomId4, userId3);
setDMRoom(client, roomId4, userId3);
});
it("should update the account data accordingly", () => {
@ -89,7 +89,7 @@ describe("setDMRoom", () => {
describe("when trying to add a DM, that already exists", () => {
beforeEach(() => {
setDMRoom(roomId1, userId1);
setDMRoom(client, roomId1, userId1);
});
it("should not update the account data", () => {
@ -99,7 +99,7 @@ describe("setDMRoom", () => {
describe("when removing an existing DM", () => {
beforeEach(() => {
setDMRoom(roomId1, null);
setDMRoom(client, roomId1, null);
});
it("should update the account data accordingly", () => {
@ -112,7 +112,7 @@ describe("setDMRoom", () => {
describe("when removing an unknown room", () => {
beforeEach(() => {
setDMRoom(roomId4, null);
setDMRoom(client, roomId4, null);
});
it("should not update the account data", () => {
@ -123,7 +123,7 @@ describe("setDMRoom", () => {
describe("when the direct event is undefined", () => {
beforeEach(() => {
mocked(client.getAccountData).mockReturnValue(undefined);
setDMRoom(roomId1, userId1);
setDMRoom(client, roomId1, userId1);
});
it("should update the account data accordingly", () => {
@ -139,7 +139,7 @@ describe("setDMRoom", () => {
mocked(client.getAccountData).mockReturnValue({
getContent: jest.fn(),
});
setDMRoom(roomId1, userId1);
setDMRoom(client, roomId1, userId1);
});
it("should update the account data accordingly", () => {

View file

@ -66,7 +66,7 @@ describe("Terms", function () {
},
});
const interactionCallback = jest.fn().mockResolvedValue([]);
await startTermsFlow([IM_SERVICE_ONE], interactionCallback);
await startTermsFlow(mockClient, [IM_SERVICE_ONE], interactionCallback);
expect(interactionCallback).toHaveBeenCalledWith(
[
@ -97,7 +97,7 @@ describe("Terms", function () {
mockClient.agreeToTerms;
const interactionCallback = jest.fn();
await startTermsFlow([IM_SERVICE_ONE], interactionCallback);
await startTermsFlow(mockClient, [IM_SERVICE_ONE], interactionCallback);
expect(interactionCallback).not.toHaveBeenCalled();
expect(mockClient.agreeToTerms).toHaveBeenCalledWith(SERVICE_TYPES.IM, "https://imone.test", "a token token", [
@ -122,7 +122,7 @@ describe("Terms", function () {
});
const interactionCallback = jest.fn().mockResolvedValue(["http://example.com/one", "http://example.com/two"]);
await startTermsFlow([IM_SERVICE_ONE], interactionCallback);
await startTermsFlow(mockClient, [IM_SERVICE_ONE], interactionCallback);
expect(interactionCallback).toHaveBeenCalledWith(
[
@ -168,7 +168,7 @@ describe("Terms", function () {
});
const interactionCallback = jest.fn().mockResolvedValue(["http://example.com/one", "http://example.com/two"]);
await startTermsFlow([IM_SERVICE_ONE, IM_SERVICE_TWO], interactionCallback);
await startTermsFlow(mockClient, [IM_SERVICE_ONE, IM_SERVICE_TWO], interactionCallback);
expect(interactionCallback).toHaveBeenCalledWith(
[

View file

@ -500,7 +500,7 @@ describe("<DeviceItem />", () => {
await userEvent.click(button);
expect(mockVerifyDevice).toHaveBeenCalledTimes(1);
expect(mockVerifyDevice).toHaveBeenCalledWith(defaultUser, device);
expect(mockVerifyDevice).toHaveBeenCalledWith(mockClient, defaultUser, device);
});
it("with display name", async () => {