From 1cb5fff5a17771ef0135a70653926ecbfe03c378 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 12 Jul 2023 11:39:33 +0100 Subject: [PATCH] Improve types (#3589) * Improve types * Improve coverage --- spec/integ/matrix-client-methods.spec.ts | 465 +++++++++++--------- src/client.ts | 56 +-- src/crypto/CrossSigning.ts | 9 +- src/crypto/index.ts | 13 +- src/http-api/fetch.ts | 4 +- src/http-api/interface.ts | 2 + src/rendezvous/MSC3906Rendezvous.ts | 13 +- src/webrtc/stats/media/mediaTrackHandler.ts | 3 +- 8 files changed, 319 insertions(+), 246 deletions(-) diff --git a/spec/integ/matrix-client-methods.spec.ts b/spec/integ/matrix-client-methods.spec.ts index 48dcccba9..18e02624f 100644 --- a/spec/integ/matrix-client-methods.spec.ts +++ b/spec/integ/matrix-client-methods.spec.ts @@ -33,9 +33,9 @@ describe("MatrixClient", function () { const accessToken = "aseukfgwef"; const idServerDomain = "identity.localhost"; // not a real server const identityAccessToken = "woop-i-am-a-secret"; - let client: MatrixClient | undefined; - let httpBackend: HttpBackend | undefined; - let store: MemoryStore | undefined; + let client: MatrixClient; + let httpBackend: HttpBackend; + let store: MemoryStore; const defaultClientOpts: IStoredClientOpts = { threadSupport: false, @@ -59,8 +59,8 @@ describe("MatrixClient", function () { }); afterEach(function () { - httpBackend!.verifyNoOutstandingExpectation(); - return httpBackend!.stop(); + httpBackend.verifyNoOutstandingExpectation(); + return httpBackend.stop(); }); describe("uploadContent", function () { @@ -72,7 +72,7 @@ describe("MatrixClient", function () { }; it("should upload the file", function () { - httpBackend! + httpBackend .when("POST", "/_matrix/media/r0/upload") .check(function (req) { expect(req.rawData).toEqual(buf); @@ -86,11 +86,11 @@ describe("MatrixClient", function () { }) .respond(200, '{"content_uri": "content"}', true); - const prom = client!.uploadContent(file, opts); + const prom = client.uploadContent(file, opts); expect(prom).toBeTruthy(); - const uploads = client!.getCurrentUploads(); + const uploads = client.getCurrentUploads(); expect(uploads.length).toEqual(1); expect(uploads[0].promise).toBe(prom); expect(uploads[0].loaded).toEqual(0); @@ -98,16 +98,16 @@ describe("MatrixClient", function () { const prom2 = prom.then(function (response) { expect(response.content_uri).toEqual("content"); - const uploads = client!.getCurrentUploads(); + const uploads = client.getCurrentUploads(); expect(uploads.length).toEqual(0); }); - httpBackend!.flush(""); + httpBackend.flush(""); return prom2; }); it("should parse errors into a MatrixError", function () { - httpBackend! + httpBackend .when("POST", "/_matrix/media/r0/upload") .check(function (req) { expect(req.rawData).toEqual(buf); @@ -119,7 +119,7 @@ describe("MatrixClient", function () { error: "broken", }); - const prom = client!.uploadContent(file, opts).then( + const prom = client.uploadContent(file, opts).then( function (response) { throw Error("request not failed"); }, @@ -130,30 +130,30 @@ describe("MatrixClient", function () { }, ); - httpBackend!.flush(""); + httpBackend.flush(""); return prom; }); it("should return a promise which can be cancelled", async () => { - const prom = client!.uploadContent(file, opts); + const prom = client.uploadContent(file, opts); - const uploads = client!.getCurrentUploads(); + const uploads = client.getCurrentUploads(); expect(uploads.length).toEqual(1); expect(uploads[0].promise).toBe(prom); expect(uploads[0].loaded).toEqual(0); - const r = client!.cancelUpload(prom); + const r = client.cancelUpload(prom); expect(r).toBe(true); await expect(prom).rejects.toThrow("Aborted"); - expect(client!.getCurrentUploads()).toHaveLength(0); + expect(client.getCurrentUploads()).toHaveLength(0); }); }); describe("joinRoom", function () { it("should no-op if you've already joined a room", function () { const roomId = "!foo:bar"; - const room = new Room(roomId, client!, userId); - client!.fetchRoomEvent = () => + const room = new Room(roomId, client, userId); + client.fetchRoomEvent = () => Promise.resolve({ type: "test", content: {}, @@ -166,10 +166,10 @@ describe("MatrixClient", function () { event: true, }), ]); - httpBackend!.verifyNoOutstandingRequests(); - store!.storeRoom(room); - client!.joinRoom(roomId); - httpBackend!.verifyNoOutstandingRequests(); + httpBackend.verifyNoOutstandingRequests(); + store.storeRoom(room); + client.joinRoom(roomId); + httpBackend.verifyNoOutstandingRequests(); }); it("should send request to inviteSignUrl if specified", async () => { @@ -183,24 +183,24 @@ describe("MatrixClient", function () { signatures: {}, }; - httpBackend! + httpBackend .when("POST", inviteSignUrl) .check((request) => { - expect(request.queryParams?.mxid).toEqual(client!.getUserId()); + expect(request.queryParams?.mxid).toEqual(client.getUserId()); }) .respond(200, signature); - httpBackend! + httpBackend .when("POST", "/join/" + encodeURIComponent(roomId)) .check((request) => { expect(request.data.third_party_signed).toEqual(signature); }) .respond(200, { room_id: roomId }); - const prom = client!.joinRoom(roomId, { + const prom = client.joinRoom(roomId, { inviteSignUrl, viaServers, }); - await httpBackend!.flushAllExpected(); + await httpBackend.flushAllExpected(); expect((await prom).roomId).toBe(roomId); }); }); @@ -212,10 +212,10 @@ describe("MatrixClient", function () { const filter = Filter.fromJson(userId, filterId, { event_format: "client", }); - store!.storeFilter(filter); - const gotFilter = await client!.getFilter(userId, filterId, true); + store.storeFilter(filter); + const gotFilter = await client.getFilter(userId, filterId, true); expect(gotFilter).toEqual(filter); - httpBackend!.verifyNoOutstandingRequests(); + httpBackend.verifyNoOutstandingRequests(); }); it("should do an HTTP request if !allowCached even if one exists", async () => { @@ -223,15 +223,15 @@ describe("MatrixClient", function () { event_format: "federation", }; - httpBackend! + httpBackend .when("GET", "/user/" + encodeURIComponent(userId) + "/filter/" + filterId) .respond(200, httpFilterDefinition); const storeFilter = Filter.fromJson(userId, filterId, { event_format: "client", }); - store!.storeFilter(storeFilter); - const [gotFilter] = await Promise.all([client!.getFilter(userId, filterId, false), httpBackend!.flush("")]); + store.storeFilter(storeFilter); + const [gotFilter] = await Promise.all([client.getFilter(userId, filterId, false), httpBackend.flush("")]); expect(gotFilter.getDefinition()).toEqual(httpFilterDefinition); }); @@ -239,14 +239,14 @@ describe("MatrixClient", function () { const httpFilterDefinition = { event_format: "federation", }; - expect(store!.getFilter(userId, filterId)).toBe(null); + expect(store.getFilter(userId, filterId)).toBe(null); - httpBackend! + httpBackend .when("GET", "/user/" + encodeURIComponent(userId) + "/filter/" + filterId) .respond(200, httpFilterDefinition); - const [gotFilter] = await Promise.all([client!.getFilter(userId, filterId, true), httpBackend!.flush("")]); + const [gotFilter] = await Promise.all([client.getFilter(userId, filterId, true), httpBackend.flush("")]); expect(gotFilter.getDefinition()).toEqual(httpFilterDefinition); - expect(store!.getFilter(userId, filterId)).toBeTruthy(); + expect(store.getFilter(userId, filterId)).toBeTruthy(); }); }); @@ -254,13 +254,13 @@ describe("MatrixClient", function () { const filterId = "f1llllllerid"; it("should do an HTTP request and then store the filter", async () => { - expect(store!.getFilter(userId, filterId)).toBe(null); + expect(store.getFilter(userId, filterId)).toBe(null); const filterDefinition = { event_format: "client" as IFilterDefinition["event_format"], }; - httpBackend! + httpBackend .when("POST", "/user/" + encodeURIComponent(userId) + "/filter") .check(function (req) { expect(req.data).toEqual(filterDefinition); @@ -269,9 +269,9 @@ describe("MatrixClient", function () { filter_id: filterId, }); - const [gotFilter] = await Promise.all([client!.createFilter(filterDefinition), httpBackend!.flush("")]); + const [gotFilter] = await Promise.all([client.createFilter(filterDefinition), httpBackend.flush("")]); expect(gotFilter.getDefinition()).toEqual(filterDefinition); - expect(store!.getFilter(userId, filterId)).toEqual(gotFilter); + expect(store.getFilter(userId, filterId)).toEqual(gotFilter); }); }); @@ -300,10 +300,10 @@ describe("MatrixClient", function () { }, }; - client!.searchMessageText({ + client.searchMessageText({ query: "monkeys", }); - httpBackend! + httpBackend .when("POST", "/search") .check(function (req) { expect(req.data).toEqual({ @@ -316,7 +316,7 @@ describe("MatrixClient", function () { }) .respond(200, response); - return httpBackend!.flush(""); + return httpBackend.flush(""); }); describe("should filter out context from different timelines (threads)", () => { @@ -386,7 +386,7 @@ describe("MatrixClient", function () { results: [], highlights: [], }; - client!.processRoomEventsSearch(data, response); + client.processRoomEventsSearch(data, response); expect(data.results).toHaveLength(1); expect(data.results[0].context.getTimeline()).toHaveLength(2); @@ -450,7 +450,7 @@ describe("MatrixClient", function () { results: [], highlights: [], }; - client!.processRoomEventsSearch(data, response); + client.processRoomEventsSearch(data, response); expect(data.results).toHaveLength(1); expect(data.results[0].context.getTimeline()).toHaveLength(1); @@ -512,7 +512,7 @@ describe("MatrixClient", function () { results: [], highlights: [], }; - client!.processRoomEventsSearch(data, response); + client.processRoomEventsSearch(data, response); expect(data.results).toHaveLength(1); expect(data.results[0].context.getTimeline()).toHaveLength(1); @@ -530,17 +530,17 @@ describe("MatrixClient", function () { beforeEach(function () { // running initCrypto should trigger a key upload - httpBackend!.when("POST", "/keys/upload").respond(200, {}); - return Promise.all([client!.initCrypto(), httpBackend!.flush("/keys/upload", 1)]); + httpBackend.when("POST", "/keys/upload").respond(200, {}); + return Promise.all([client.initCrypto(), httpBackend.flush("/keys/upload", 1)]); }); afterEach(() => { - client!.stopClient(); + client.stopClient(); }); it("should do an HTTP request and then store the keys", function () { const ed25519key = "7wG2lzAqbjcyEkOP7O4gU7ItYcn+chKzh5sT/5r2l78"; - // ed25519key = client!.getDeviceEd25519Key(); + // ed25519key = client.getDeviceEd25519Key(); const borisKeys = { dev1: { algorithms: ["1"], @@ -580,7 +580,7 @@ describe("MatrixClient", function () { var b = JSON.parse(JSON.stringify(o)); delete(b.signatures); delete(b.unsigned); - return client!.crypto.olmDevice.sign(anotherjson.stringify(b)); + return client.crypto.olmDevice.sign(anotherjson.stringify(b)); }; logger.log("Ed25519: " + ed25519key); @@ -588,7 +588,7 @@ describe("MatrixClient", function () { logger.log("chaz:", sign(chazKeys.dev2)); */ - httpBackend! + httpBackend .when("POST", "/keys/query") .check(function (req) { expect(req.data).toEqual({ @@ -605,7 +605,7 @@ describe("MatrixClient", function () { }, }); - const prom = client!.downloadKeys(["boris", "chaz"]).then(function (res) { + const prom = client.downloadKeys(["boris", "chaz"]).then(function (res) { assertObjectContains(res.get("boris")!.get("dev1")!, { verified: 0, // DeviceVerification.UNVERIFIED keys: { "ed25519:dev1": ed25519key }, @@ -621,7 +621,7 @@ describe("MatrixClient", function () { }); }); - httpBackend!.flush(""); + httpBackend.flush(""); return prom; }); }); @@ -629,16 +629,16 @@ describe("MatrixClient", function () { describe("deleteDevice", function () { const auth = { identifier: 1 }; it("should pass through an auth dict", function () { - httpBackend! + httpBackend .when("DELETE", "/_matrix/client/r0/devices/my_device") .check(function (req) { expect(req.data).toEqual({ auth: auth }); }) .respond(200); - const prom = client!.deleteDevice("my_device", auth); + const prom = client.deleteDevice("my_device", auth); - httpBackend!.flush(""); + httpBackend.flush(""); return prom; }); }); @@ -646,7 +646,7 @@ describe("MatrixClient", function () { describe("partitionThreadedEvents", function () { let room: Room; beforeEach(() => { - room = new Room("!STrMRsukXHtqQdSeHa:matrix.org", client!, userId); + room = new Room("!STrMRsukXHtqQdSeHa:matrix.org", client, userId); }); it("returns empty arrays when given an empty arrays", function () { @@ -658,7 +658,7 @@ describe("MatrixClient", function () { it("copies pre-thread in-timeline vote events onto both timelines", function () { // @ts-ignore setting private property - client!.clientOpts = { + client.clientOpts = { ...defaultClientOpts, threadSupport: true, }; @@ -689,7 +689,7 @@ describe("MatrixClient", function () { it("copies pre-thread in-timeline reactions onto both timelines", function () { // @ts-ignore setting private property - client!.clientOpts = { + client.clientOpts = { ...defaultClientOpts, threadSupport: true, }; @@ -713,7 +713,7 @@ describe("MatrixClient", function () { it("copies post-thread in-timeline vote events onto both timelines", function () { // @ts-ignore setting private property - client!.clientOpts = { + client.clientOpts = { ...defaultClientOpts, threadSupport: true, }; @@ -737,7 +737,7 @@ describe("MatrixClient", function () { it("copies post-thread in-timeline reactions onto both timelines", function () { // @ts-ignore setting private property - client!.clientOpts = { + client.clientOpts = { ...defaultClientOpts, threadSupport: true, }; @@ -761,7 +761,7 @@ describe("MatrixClient", function () { it("sends room state events to the main timeline only", function () { // @ts-ignore setting private property - client!.clientOpts = { + client.clientOpts = { ...defaultClientOpts, threadSupport: true, }; @@ -818,7 +818,7 @@ describe("MatrixClient", function () { it("sends redactions of reactions to thread responses to thread timeline only", () => { // @ts-ignore setting private property - client!.clientOpts = { + client.clientOpts = { ...defaultClientOpts, threadSupport: true, }; @@ -844,7 +844,7 @@ describe("MatrixClient", function () { it("sends reply to reply to thread root outside of thread to main timeline only", () => { // @ts-ignore setting private property - client!.clientOpts = { + client.clientOpts = { ...defaultClientOpts, threadSupport: true, }; @@ -865,7 +865,7 @@ describe("MatrixClient", function () { it("sends reply to thread responses to main timeline only", () => { // @ts-ignore setting private property - client!.clientOpts = { + client.clientOpts = { ...defaultClientOpts, threadSupport: true, }; @@ -894,9 +894,9 @@ describe("MatrixClient", function () { }, ]; - const prom = client!.getThirdpartyUser("irc", {}); - httpBackend!.when("GET", "/thirdparty/user/irc").respond(200, response); - await httpBackend!.flush(""); + const prom = client.getThirdpartyUser("irc", {}); + httpBackend.when("GET", "/thirdparty/user/irc").respond(200, response); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); }); @@ -911,9 +911,9 @@ describe("MatrixClient", function () { }, ]; - const prom = client!.getThirdpartyLocation("irc", {}); - httpBackend!.when("GET", "/thirdparty/location/irc").respond(200, response); - await httpBackend!.flush(""); + const prom = client.getThirdpartyLocation("irc", {}); + httpBackend.when("GET", "/thirdparty/location/irc").respond(200, response); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); }); @@ -924,10 +924,10 @@ describe("MatrixClient", function () { pushers: [], }; - const prom = client!.getPushers(); - httpBackend!.when("GET", "/_matrix/client/versions").respond(200, {}); - httpBackend!.when("GET", "/pushers").respond(200, response); - await httpBackend!.flush(""); + const prom = client.getPushers(); + httpBackend.when("GET", "/_matrix/client/versions").respond(200, {}); + httpBackend.when("GET", "/pushers").respond(200, response); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); }); @@ -939,15 +939,15 @@ describe("MatrixClient", function () { left: [], }; - const prom = client!.getKeyChanges("old", "new"); - httpBackend! + const prom = client.getKeyChanges("old", "new"); + httpBackend .when("GET", "/keys/changes") .check((req) => { expect(req.queryParams?.from).toEqual("old"); expect(req.queryParams?.to).toEqual("new"); }) .respond(200, response); - await httpBackend!.flush(""); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); }); @@ -958,9 +958,9 @@ describe("MatrixClient", function () { devices: [], }; - const prom = client!.getDevices(); - httpBackend!.when("GET", "/devices").respond(200, response); - await httpBackend!.flush(""); + const prom = client.getDevices(); + httpBackend.when("GET", "/devices").respond(200, response); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); }); @@ -974,9 +974,9 @@ describe("MatrixClient", function () { last_seen_ts: 1, }; - const prom = client!.getDevice("DEADBEEF"); - httpBackend!.when("GET", "/devices/DEADBEEF").respond(200, response); - await httpBackend!.flush(""); + const prom = client.getDevice("DEADBEEF"); + httpBackend.when("GET", "/devices/DEADBEEF").respond(200, response); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); }); @@ -987,9 +987,9 @@ describe("MatrixClient", function () { threepids: [], }; - const prom = client!.getThreePids(); - httpBackend!.when("GET", "/account/3pid").respond(200, response); - await httpBackend!.flush(""); + const prom = client.getThreePids(); + httpBackend.when("GET", "/account/3pid").respond(200, response); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); }); @@ -997,9 +997,9 @@ describe("MatrixClient", function () { describe("deleteAlias", () => { it("should hit the expected API endpoint", async () => { const response = {}; - const prom = client!.deleteAlias("#foo:bar"); - httpBackend!.when("DELETE", "/directory/room/" + encodeURIComponent("#foo:bar")).respond(200, response); - await httpBackend!.flush(""); + const prom = client.deleteAlias("#foo:bar"); + httpBackend.when("DELETE", "/directory/room/" + encodeURIComponent("#foo:bar")).respond(200, response); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); }); @@ -1007,10 +1007,10 @@ describe("MatrixClient", function () { describe("deleteRoomTag", () => { it("should hit the expected API endpoint", async () => { const response = {}; - const prom = client!.deleteRoomTag("!roomId:server", "u.tag"); + const prom = client.deleteRoomTag("!roomId:server", "u.tag"); const url = `/user/${encodeURIComponent(userId)}/rooms/${encodeURIComponent("!roomId:server")}/tags/u.tag`; - httpBackend!.when("DELETE", url).respond(200, response); - await httpBackend!.flush(""); + httpBackend.when("DELETE", url).respond(200, response); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); }); @@ -1025,10 +1025,10 @@ describe("MatrixClient", function () { }, }; - const prom = client!.getRoomTags("!roomId:server"); + const prom = client.getRoomTags("!roomId:server"); const url = `/user/${encodeURIComponent(userId)}/rooms/${encodeURIComponent("!roomId:server")}/tags`; - httpBackend!.when("GET", url).respond(200, response); - await httpBackend!.flush(""); + httpBackend.when("GET", url).respond(200, response); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); }); @@ -1040,12 +1040,12 @@ describe("MatrixClient", function () { submit_url: "https://foobar.matrix/_matrix/matrix", }; - httpBackend!.when("GET", "/_matrix/client/versions").respond(200, { + httpBackend.when("GET", "/_matrix/client/versions").respond(200, { versions: ["r0.6.0"], }); - const prom = client!.requestRegisterEmailToken("bob@email", "secret", 1); - httpBackend! + const prom = client.requestRegisterEmailToken("bob@email", "secret", 1); + httpBackend .when("POST", "/register/email/requestToken") .check((req) => { expect(req.data).toStrictEqual({ @@ -1055,7 +1055,7 @@ describe("MatrixClient", function () { }); }) .respond(200, response); - await httpBackend!.flush(""); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); }); @@ -1064,11 +1064,11 @@ describe("MatrixClient", function () { it("should supply an id_access_token", async () => { const targetEmail = "gerald@example.org"; - httpBackend!.when("GET", "/_matrix/client/versions").respond(200, { + httpBackend.when("GET", "/_matrix/client/versions").respond(200, { versions: ["r0.6.0"], }); - httpBackend! + httpBackend .when("POST", "/invite") .check((req) => { expect(req.data).toStrictEqual({ @@ -1080,8 +1080,8 @@ describe("MatrixClient", function () { }) .respond(200, {}); - const prom = client!.inviteByThreePid("!room:example.org", "email", targetEmail); - await httpBackend!.flush(""); + const prom = client.inviteByThreePid("!room:example.org", "email", targetEmail); + await httpBackend.flush(""); await prom; // returns empty object, so no validation needed }); }); @@ -1103,11 +1103,11 @@ describe("MatrixClient", function () { ], }; - httpBackend!.when("GET", "/_matrix/client/versions").respond(200, { + httpBackend.when("GET", "/_matrix/client/versions").respond(200, { versions: ["r0.6.0"], }); - httpBackend! + httpBackend .when("POST", "/createRoom") .check((req) => { expect(req.data).toMatchObject({ @@ -1122,57 +1122,57 @@ describe("MatrixClient", function () { }) .respond(200, response); - const prom = client!.createRoom(input); - await httpBackend!.flush(""); + const prom = client.createRoom(input); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); }); describe("requestLoginToken", () => { it("should hit the expected API endpoint with UIA", async () => { - httpBackend! + httpBackend .when("GET", "/capabilities") .respond(200, { capabilities: { "org.matrix.msc3882.get_login_token": { enabled: true } } }); const response = {}; const uiaData = {}; - const prom = client!.requestLoginToken(uiaData); - httpBackend! + const prom = client.requestLoginToken(uiaData); + httpBackend .when("POST", "/unstable/org.matrix.msc3882/login/get_token", { auth: uiaData }) .respond(200, response); - await httpBackend!.flush(""); + await httpBackend.flush(""); expect(await prom).toStrictEqual(response); }); it("should hit the expected API endpoint without UIA", async () => { - httpBackend! + httpBackend .when("GET", "/capabilities") .respond(200, { capabilities: { "org.matrix.msc3882.get_login_token": { enabled: true } } }); const response = { login_token: "xyz", expires_in_ms: 5000 }; - const prom = client!.requestLoginToken(); - httpBackend!.when("POST", "/unstable/org.matrix.msc3882/login/get_token", {}).respond(200, response); - await httpBackend!.flush(""); + const prom = client.requestLoginToken(); + httpBackend.when("POST", "/unstable/org.matrix.msc3882/login/get_token", {}).respond(200, response); + await httpBackend.flush(""); // check that expires_in has been populated for compatibility with r0 expect(await prom).toStrictEqual({ ...response, expires_in: 5 }); }); it("should hit the r1 endpoint when capability is disabled", async () => { - httpBackend! + httpBackend .when("GET", "/capabilities") .respond(200, { capabilities: { "org.matrix.msc3882.get_login_token": { enabled: false } } }); const response = { login_token: "xyz", expires_in_ms: 5000 }; - const prom = client!.requestLoginToken(); - httpBackend!.when("POST", "/unstable/org.matrix.msc3882/login/get_token", {}).respond(200, response); - await httpBackend!.flush(""); + const prom = client.requestLoginToken(); + httpBackend.when("POST", "/unstable/org.matrix.msc3882/login/get_token", {}).respond(200, response); + await httpBackend.flush(""); // check that expires_in has been populated for compatibility with r0 expect(await prom).toStrictEqual({ ...response, expires_in: 5 }); }); it("should hit the r0 endpoint for fallback", async () => { - httpBackend!.when("GET", "/capabilities").respond(200, {}); + httpBackend.when("GET", "/capabilities").respond(200, {}); const response = { login_token: "xyz", expires_in: 5 }; - const prom = client!.requestLoginToken(); - httpBackend!.when("POST", "/unstable/org.matrix.msc3882/login/token", {}).respond(200, response); - await httpBackend!.flush(""); + const prom = client.requestLoginToken(); + httpBackend.when("POST", "/unstable/org.matrix.msc3882/login/token", {}).respond(200, response); + await httpBackend.flush(""); // check that expires_in has been populated for compatibility with r1 expect(await prom).toStrictEqual({ ...response, expires_in_ms: 5000 }); }); @@ -1180,18 +1180,18 @@ describe("MatrixClient", function () { describe("logout", () => { it("should abort pending requests when called with stopClient=true", async () => { - httpBackend!.when("POST", "/logout").respond(200, {}); + httpBackend.when("POST", "/logout").respond(200, {}); const fn = jest.fn(); - client!.http.request(Method.Get, "/test").catch(fn); - client!.logout(true); - await httpBackend!.flush(undefined); + client.http.request(Method.Get, "/test").catch(fn); + client.logout(true); + await httpBackend.flush(undefined); expect(fn).toHaveBeenCalled(); }); }); describe("sendHtmlEmote", () => { it("should send valid html emote", async () => { - httpBackend! + httpBackend .when("PUT", "/send") .check((req) => { expect(req.data).toStrictEqual({ @@ -1202,15 +1202,15 @@ describe("MatrixClient", function () { }); }) .respond(200, { event_id: "$foobar" }); - const prom = client!.sendHtmlEmote("!room:server", "Body", "