Skip to content

Commit

Permalink
Prevent console writes after tests?
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed May 29, 2022
1 parent 9527da0 commit e55dfc9
Show file tree
Hide file tree
Showing 10 changed files with 453 additions and 226 deletions.
3 changes: 2 additions & 1 deletion test/AdminApisTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ describe('AdminApis', () => {
return response;
});

http.flushAllExpected();
const flush = http.flushAllExpected();
const result = await client.whoisUser(userId);
expect(result).toMatchObject(<any>response);
await flush;
});
});
});
27 changes: 18 additions & 9 deletions test/DMsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('DMs', () => {
return {};
});

http.flushAllExpected();
const flush = http.flushAllExpected();

const accountHandleProm = new Promise<void>(resolve => {
const orig = (<any>dms).updateFromAccountData.bind(dms);
Expand Down Expand Up @@ -76,6 +76,7 @@ describe('DMs', () => {

expect(dms.isDm(dmRoomId1)).toBe(true);
expect(dms.isDm(dmRoomId2)).toBe(true);
await flush;
});

it('should update from account data when requested', async () => {
Expand All @@ -93,10 +94,11 @@ describe('DMs', () => {
// noinspection TypeScriptValidateJSTypes
http.when("GET", `/user/${encodeURIComponent(selfUserId)}/account_data/m.direct`).respond(200, accountDataDms);

http.flushAllExpected();
const flush = http.flushAllExpected();
expect(dms.isDm(dmRoomId)).toBe(false);
await dms.update();
expect(dms.isDm(dmRoomId)).toBe(true);
await flush;
});

it('should not fail to update when the account data is missing/fails', async () => {
Expand All @@ -109,10 +111,11 @@ describe('DMs', () => {
// noinspection TypeScriptValidateJSTypes
http.when("GET", `/user/${encodeURIComponent(selfUserId)}/account_data/m.direct`).respond(404);

http.flushAllExpected();
const flush = http.flushAllExpected();
expect(dms.isDm(dmRoomId)).toBe(false);
await dms.update();
expect(dms.isDm(dmRoomId)).toBe(false);
await flush;
});

it('should create a DM if one does not exist', async () => {
Expand Down Expand Up @@ -143,12 +146,13 @@ describe('DMs', () => {
return {};
});

http.flushAllExpected();
const flush = http.flushAllExpected();

expect(dms.isDm(dmRoomId)).toBe(false);
const roomId = await dms.getOrCreateDm(dmUserId);
expect(roomId).toEqual(dmRoomId);
expect(dms.isDm(dmRoomId)).toBe(true);
await flush;
});

it('should call the optional create room function when provided', async () => {
Expand All @@ -172,13 +176,14 @@ describe('DMs', () => {
return {};
});

http.flushAllExpected();
const flush = http.flushAllExpected();

expect(dms.isDm(dmRoomId)).toBe(false);
const roomId = await dms.getOrCreateDm(dmUserId, fn);
expect(roomId).toEqual(dmRoomId);
expect(dms.isDm(dmRoomId)).toBe(true);
expect(fn.callCount).toBe(1);
await flush;
});

it('should try to patch up DMs when a DM is potentially known', async () => {
Expand Down Expand Up @@ -251,7 +256,7 @@ describe('DMs', () => {
return {};
});

http.flushAllExpected();
const flush = http.flushAllExpected();

await dms.update();
expect(dms.isDm(dmRoomId)).toBe(true);
Expand All @@ -260,6 +265,7 @@ describe('DMs', () => {
expect(roomId).toEqual(dmRoomId);
expect(dms.isDm(dmRoomId)).toBe(true);
expect(dms.isDm(deadRoomId)).toBe(false);
await flush;
});

it('should use the cache if a DM already exists', async () => {
Expand All @@ -280,13 +286,14 @@ describe('DMs', () => {
// noinspection TypeScriptValidateJSTypes
http.when("GET", `/user/${encodeURIComponent(selfUserId)}/account_data/m.direct`).respond(200, accountDataDms);

http.flushAllExpected();
const flush = http.flushAllExpected();

await dms.update();
expect(dms.isDm(dmRoomId)).toBe(true);
const roomId = await dms.getOrCreateDm(dmUserId);
expect(roomId).toEqual(dmRoomId);
expect(dms.isDm(dmRoomId)).toBe(true);
await flush;
});

it('should create an encrypted DM if supported', async () => {
Expand Down Expand Up @@ -343,12 +350,13 @@ describe('DMs', () => {
return {};
});

http.flushAllExpected();
const flush = http.flushAllExpected();

expect(dms.isDm(dmRoomId)).toBe(false);
const roomId = await dms.getOrCreateDm(dmUserId);
expect(roomId).toEqual(dmRoomId);
expect(dms.isDm(dmRoomId)).toBe(true);
await flush;
});

it('should create an unencrypted DM when the target user has no devices', async () => {
Expand Down Expand Up @@ -393,11 +401,12 @@ describe('DMs', () => {
return {};
});

http.flushAllExpected();
const flush = http.flushAllExpected();

expect(dms.isDm(dmRoomId)).toBe(false);
const roomId = await dms.getOrCreateDm(dmUserId);
expect(roomId).toEqual(dmRoomId);
expect(dms.isDm(dmRoomId)).toBe(true);
await flush;
});
});
Loading

0 comments on commit e55dfc9

Please sign in to comment.