mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-06-04 06:41:18 +00:00
c11fb6ef06
This was introduced in https://github.com/Gnuxie/Draupnir/pull/54/ (and therefore 1.83.0). Essentially we forgot to remove the room from the protected rooms set, when the remove command was used. Ontop of this something to note is that during testing it is clear that the protected rooms set is loaded when configuring mjolnir, not when starting it. This is problematic as it means setup code in `fixtures.ts` does not actually wipe the protected rooms set.
46 lines
2.4 KiB
TypeScript
46 lines
2.4 KiB
TypeScript
import { read as configRead } from "../../src/config";
|
|
import { WATCHED_LISTS_EVENT_TYPE } from "../../src/models/PolicyList";
|
|
import { patchMatrixClient } from "../../src/utils";
|
|
import { makeMjolnir, teardownManagementRoom } from "./mjolnirSetupUtils";
|
|
|
|
patchMatrixClient();
|
|
|
|
// When Mjolnir starts (src/index.ts) it clobbers the config by resolving the management room
|
|
// alias specified in the config (config.managementRoom) and overwriting that with the room ID.
|
|
// Unfortunately every piece of code importing that config imports the same instance, including
|
|
// testing code, which is problematic when we want to create a fresh management room for each test.
|
|
// So there is some code in here to "undo" the mutation after we stop Mjolnir syncing.
|
|
export const mochaHooks = {
|
|
beforeEach: [
|
|
async function() {
|
|
console.error("---- entering test", JSON.stringify(this.currentTest.title)); // Makes MatrixClient error logs a bit easier to parse.
|
|
console.log("mochaHooks.beforeEach");
|
|
// Sometimes it takes a little longer to register users.
|
|
this.timeout(30000);
|
|
const config = this.config = configRead();
|
|
this.managementRoomAlias = config.managementRoom;
|
|
this.mjolnir = await makeMjolnir(config);
|
|
config.RUNTIME.client = this.mjolnir.client;
|
|
await Promise.all([
|
|
this.mjolnir.client.setAccountData('org.matrix.mjolnir.protected_rooms', { rooms: [] }),
|
|
this.mjolnir.client.setAccountData(WATCHED_LISTS_EVENT_TYPE, { references: [] }),
|
|
]);
|
|
await this.mjolnir.start();
|
|
console.log("mochaHooks.beforeEach DONE");
|
|
}
|
|
],
|
|
afterEach: [
|
|
async function() {
|
|
this.timeout(10000)
|
|
await this.mjolnir.stop();
|
|
await Promise.all([
|
|
this.mjolnir.client.setAccountData('org.matrix.mjolnir.protected_rooms', { rooms: [] }),
|
|
this.mjolnir.client.setAccountData(WATCHED_LISTS_EVENT_TYPE, { references: [] }),
|
|
]);
|
|
// remove alias from management room and leave it.
|
|
await teardownManagementRoom(this.mjolnir.client, this.mjolnir.managementRoomId, this.managementRoomAlias);
|
|
console.error("---- completed test", JSON.stringify(this.currentTest.title), "\n\n"); // Makes MatrixClient error logs a bit easier to parse.
|
|
}
|
|
]
|
|
};
|