Skip to content

Commit a1b046b

Browse files
author
Kerry
authored
test typescriptification - spec/integ (#2714)
* renamed: spec/integ/devicelist-integ.spec.js -> spec/integ/devicelist-integ.spec.ts * fix ts issue in devicelist-integ.spec * renamed: spec/integ/matrix-client-event-emitter.spec.js -> spec/integ/matrix-client-event-emitter.spec.ts * ts issues in matrix-client-event-emitter integ * strict fixes * renamed: spec/integ/matrix-client-methods.spec.js -> spec/integ/matrix-client-methods.spec.ts * fix ts issues * renamed: spec/integ/matrix-client-opts.spec.js -> spec/integ/matrix-client-opts.spec.ts * ts fixes in matrix-client-methods / matrix-client-opts * renamed: spec/integ/matrix-client-room-timeline.spec.js -> spec/integ/matrix-client-room-timeline.spec.ts * most ts fixes in matrix-client-room-timeline * remove obsoleted prev_events from mockenvents * make xmlhttprequest ts * strict errors in matrix-client-event-timeline spec * strict in devicelist * strict fixes in matrix-client-crypto.spec * strict fixes in spec/integ/matrix-client-room-timeline * strict issues in matrix-client-opts.specc * strict issues in matrix-client-syncing * strict issues in spec/integ/megolm * strict fixes in spec/integ/matrix-client-retrying.spec * strict fixes for spec/integ/sliding-sync * eslint fixes * more strict errors sneaking in from develop * kill al httpbackends * kill matrix-client-methods.spec httpbackend properly
1 parent 3a3dcfb commit a1b046b

14 files changed

+1078
-949
lines changed

spec/browserify/setupTests.js renamed to spec/browserify/setupTests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ limitations under the License.
1515
*/
1616

1717
// stub for browser-matrix browserify tests
18+
// @ts-ignore
1819
global.XMLHttpRequest = jest.fn();
1920

2021
afterAll(() => {
2122
// clean up XMLHttpRequest mock
23+
// @ts-ignore
2224
global.XMLHttpRequest = undefined;
2325
});

spec/integ/devicelist-integ.spec.js renamed to spec/integ/devicelist-integ.spec.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe("DeviceList management:", function() {
122122
aliceTestClient.httpBackend.when(
123123
'PUT', '/send/',
124124
).respond(200, {
125-
event_id: '$event_id',
125+
event_id: '$event_id',
126126
});
127127

128128
return Promise.all([
@@ -290,8 +290,9 @@ describe("DeviceList management:", function() {
290290
aliceTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
291291
const bobStat = data.trackingStatus['@bob:xyz'];
292292

293+
// Alice should be tracking bob's device list
293294
expect(bobStat).toBeGreaterThan(
294-
0, "Alice should be tracking bob's device list",
295+
0,
295296
);
296297
});
297298
});
@@ -326,8 +327,9 @@ describe("DeviceList management:", function() {
326327
aliceTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
327328
const bobStat = data.trackingStatus['@bob:xyz'];
328329

330+
// Alice should have marked bob's device list as untracked
329331
expect(bobStat).toEqual(
330-
0, "Alice should have marked bob's device list as untracked",
332+
0,
331333
);
332334
});
333335
});
@@ -362,8 +364,9 @@ describe("DeviceList management:", function() {
362364
aliceTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
363365
const bobStat = data.trackingStatus['@bob:xyz'];
364366

367+
// Alice should have marked bob's device list as untracked
365368
expect(bobStat).toEqual(
366-
0, "Alice should have marked bob's device list as untracked",
369+
0,
367370
);
368371
});
369372
});
@@ -378,13 +381,15 @@ describe("DeviceList management:", function() {
378381
anotherTestClient.httpBackend.when('GET', '/sync').respond(
379382
200, getSyncResponse([]));
380383
await anotherTestClient.flushSync();
381-
await anotherTestClient.client.crypto.deviceList.saveIfDirty();
384+
await anotherTestClient.client?.crypto?.deviceList?.saveIfDirty();
382385

386+
// @ts-ignore accessing private property
383387
anotherTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
384-
const bobStat = data.trackingStatus['@bob:xyz'];
388+
const bobStat = data!.trackingStatus['@bob:xyz'];
385389

390+
// Alice should have marked bob's device list as untracked
386391
expect(bobStat).toEqual(
387-
0, "Alice should have marked bob's device list as untracked",
392+
0,
388393
);
389394
});
390395
} finally {

spec/integ/matrix-client-crypto.spec.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ import '../olm-loader';
3131
import { logger } from '../../src/logger';
3232
import * as testUtils from "../test-utils/test-utils";
3333
import { TestClient } from "../TestClient";
34-
import { CRYPTO_ENABLED } from "../../src/client";
34+
import { CRYPTO_ENABLED, IUploadKeysRequest } from "../../src/client";
3535
import { ClientEvent, IContent, ISendEventResponse, MatrixClient, MatrixEvent } from "../../src/matrix";
36+
import { DeviceInfo } from '../../src/crypto/deviceinfo';
3637

3738
let aliTestClient: TestClient;
3839
const roomId = "!room:localhost";
@@ -71,12 +72,12 @@ function expectQueryKeys(querier: TestClient, uploader: TestClient): Promise<num
7172
expect(uploader.deviceKeys).toBeTruthy();
7273

7374
const uploaderKeys = {};
74-
uploaderKeys[uploader.deviceId] = uploader.deviceKeys;
75+
uploaderKeys[uploader.deviceId!] = uploader.deviceKeys;
7576
querier.httpBackend.when("POST", "/keys/query")
76-
.respond(200, function(_path, content) {
77-
expect(content.device_keys[uploader.userId]).toEqual([]);
77+
.respond(200, function(_path, content: IUploadKeysRequest) {
78+
expect(content.device_keys![uploader.userId!]).toEqual([]);
7879
const result = {};
79-
result[uploader.userId] = uploaderKeys;
80+
result[uploader.userId!] = uploaderKeys;
8081
return { device_keys: result };
8182
});
8283
return querier.httpBackend.flush("/keys/query", 1);
@@ -93,10 +94,10 @@ async function expectAliClaimKeys(): Promise<void> {
9394
const keys = await bobTestClient.awaitOneTimeKeyUpload();
9495
aliTestClient.httpBackend.when(
9596
"POST", "/keys/claim",
96-
).respond(200, function(_path, content) {
97-
const claimType = content.one_time_keys[bobUserId][bobDeviceId];
97+
).respond(200, function(_path, content: IUploadKeysRequest) {
98+
const claimType = content.one_time_keys![bobUserId][bobDeviceId];
9899
expect(claimType).toEqual("signed_curve25519");
99-
let keyId = null;
100+
let keyId = '';
100101
for (keyId in keys) {
101102
if (bobTestClient.oneTimeKeys.hasOwnProperty(keyId)) {
102103
if (keyId.indexOf(claimType + ":") === 0) {
@@ -135,10 +136,10 @@ async function aliDownloadsKeys(): Promise<void> {
135136
await aliTestClient.client.crypto!.deviceList.saveIfDirty();
136137
// @ts-ignore - protected
137138
aliTestClient.client.cryptoStore.getEndToEndDeviceData(null, (data) => {
138-
const devices = data.devices[bobUserId];
139+
const devices = data!.devices[bobUserId]!;
139140
expect(devices[bobDeviceId].keys).toEqual(bobTestClient.deviceKeys.keys);
140141
expect(devices[bobDeviceId].verified).
141-
toBe(0); // DeviceVerification.UNVERIFIED
142+
toBe(DeviceInfo.DeviceVerification.UNVERIFIED);
142143
});
143144
}
144145

@@ -237,7 +238,7 @@ function sendMessage(client: MatrixClient): Promise<ISendEventResponse> {
237238

238239
async function expectSendMessageRequest(httpBackend: TestClient["httpBackend"]): Promise<IContent> {
239240
const path = "/send/m.room.encrypted/";
240-
const prom = new Promise((resolve) => {
241+
const prom = new Promise<IContent>((resolve) => {
241242
httpBackend.when("PUT", path).respond(200, function(_path, content) {
242243
resolve(content);
243244
return {
@@ -252,14 +253,14 @@ async function expectSendMessageRequest(httpBackend: TestClient["httpBackend"]):
252253
}
253254

254255
function aliRecvMessage(): Promise<void> {
255-
const message = bobMessages.shift();
256+
const message = bobMessages.shift()!;
256257
return recvMessage(
257258
aliTestClient.httpBackend, aliTestClient.client, bobUserId, message,
258259
);
259260
}
260261

261262
function bobRecvMessage(): Promise<void> {
262-
const message = aliMessages.shift();
263+
const message = aliMessages.shift()!;
263264
return recvMessage(
264265
bobTestClient.httpBackend, bobTestClient.client, aliUserId, message,
265266
);
@@ -509,7 +510,7 @@ describe("MatrixClient crypto", () => {
509510
await firstSync(aliTestClient);
510511
await aliEnablesEncryption();
511512
await aliSendsFirstMessage();
512-
const message = aliMessages.shift();
513+
const message = aliMessages.shift()!;
513514
const syncData = {
514515
next_batch: "x",
515516
rooms: {
@@ -664,11 +665,10 @@ describe("MatrixClient crypto", () => {
664665
]);
665666
logger.log(aliTestClient + ': started');
666667
httpBackend.when("POST", "/keys/upload")
667-
.respond(200, (_path, content) => {
668+
.respond(200, (_path, content: IUploadKeysRequest) => {
668669
expect(content.one_time_keys).toBeTruthy();
669670
expect(content.one_time_keys).not.toEqual({});
670-
expect(Object.keys(content.one_time_keys).length).toBeGreaterThanOrEqual(1);
671-
logger.log('received %i one-time keys', Object.keys(content.one_time_keys).length);
671+
expect(Object.keys(content.one_time_keys!).length).toBeGreaterThanOrEqual(1);
672672
// cancel futher calls by telling the client
673673
// we have more than we need
674674
return {

0 commit comments

Comments
 (0)