mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Fix bad teardowns that hang in tests. (#202)
* Fix bad teardowns and hanging test.
This commit is contained in:
parent
0cde70e846
commit
e52b59df6e
@ -90,7 +90,7 @@ async function registerNewTestUser(options: RegistrationOptions) {
|
||||
username = `mjolnir-test-user-${options.name.contains}${Math.floor(Math.random() * 100000)}`
|
||||
}
|
||||
try {
|
||||
await registerUser(username, username, username, options.isAdmin);
|
||||
await registerUser(username, username, username, Boolean(options.isAdmin));
|
||||
return username;
|
||||
} catch (e) {
|
||||
if (e?.body?.errcode === 'M_USER_IN_USE') {
|
||||
|
@ -23,7 +23,7 @@ import * as crypto from "crypto";
|
||||
const targetEventId = await targetEventThunk();
|
||||
for (let event of reactionEvents) {
|
||||
const in_reply_to = event.content['m.relates_to']?.['m.in_reply_to'];
|
||||
if (in_reply_to.event_id === targetEventId) {
|
||||
if (in_reply_to?.event_id === targetEventId) {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
@ -70,7 +70,7 @@ export async function getFirstReaction(client: MatrixClient, targetRoom: string,
|
||||
const targetEventId = await targetEventThunk();
|
||||
for (let event of reactionEvents) {
|
||||
const relates_to = event.content['m.relates_to'];
|
||||
if (relates_to.event_id === targetEventId && relates_to.key === reactionKey) {
|
||||
if (relates_to?.event_id === targetEventId && relates_to?.key === reactionKey) {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
@ -79,7 +79,7 @@ export async function getFirstReaction(client: MatrixClient, targetRoom: string,
|
||||
if (roomId !== targetRoom) return;
|
||||
if (event.type !== 'm.reaction') return;
|
||||
const relates_to = event.content['m.relates_to'];
|
||||
if (relates_to.event_id === targetEventId && relates_to.key === reactionKey) {
|
||||
if (relates_to?.event_id === targetEventId && relates_to?.key === reactionKey) {
|
||||
resolve(event)
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ import { LogService } from "matrix-bot-sdk";
|
||||
import { getFirstReaction } from "./commandUtils";
|
||||
|
||||
describe("Test: The redaction command", function () {
|
||||
// If a test has a timeout while awaitng on a promise then we never get given control back.
|
||||
afterEach(function() { this.moderator?.stop(); });
|
||||
|
||||
it('Mjölnir redacts all of the events sent by a spammer when instructed to by giving their id and a room id.', async function() {
|
||||
this.timeout(60000);
|
||||
// Create a few users and a room.
|
||||
@ -51,6 +54,7 @@ import { getFirstReaction } from "./commandUtils";
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
it('Mjölnir redacts all of the events sent by a spammer when instructed to by giving their id in multiple rooms.', async function() {
|
||||
this.timeout(60000);
|
||||
// Create a few users and a room.
|
||||
|
@ -24,6 +24,9 @@ describe("Test: Mjolnir can still sync and respond to commands while throttled",
|
||||
await resetRatelimitForUser(await this.mjolnir.client.getUserId())
|
||||
})
|
||||
afterEach(async function() {
|
||||
// If a test has a timeout while awaitng on a promise then we never get given control back.
|
||||
this.moderator?.stop();
|
||||
|
||||
await overrideRatelimitForUser(await this.mjolnir.client.getUserId());
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user