Files
Draupnir/test/integration/commands/shutdownCommandTest.ts
Aminda Suomalainen e4c02b96cd Add pre-commit configuration (#34)
* add .pre-commit-config.yaml

Signed-off-by: Aminda Suomalainen <suomalainen+git@mikaela.info>

* .editorconfig: decrease indent size for text

* .pre-commit-config.yaml: remove prettier

Signed-off-by: Aminda Suomalainen <suomalainen+git@mikaela.info>

* .editorconfig consistency.

* .pre-commit-config.yaml: restore sample hooks

* .editorconfig: disable indent_size for LICENSE & NOTICE

* pre-commit run --all-files

* tsconfig.json: tabs to spaces

* .pre-commit-config.yaml: update editorconfig-checker to 2.7.2

* .editorconfig: disable indent_size for markdown

* mjolnir-entrypoint.sh: retab

* .editorconfig: also exclude json from indent checking

* test/nginx.conf: retab

* test/integration/commands/redactCommandTest.ts: remove leading space

* retab or remove leading whitespaces for the rest of the files

* src/appservice/datastore.ts remove newlines

* test/integration/commands/roomTest.ts: remove leading space.

---------

Signed-off-by: Aminda Suomalainen <suomalainen+git@mikaela.info>
Co-authored-by: gnuxie <Gnuxie@protonmail.com>
2023-08-29 13:38:00 +01:00

57 lines
2.1 KiB
TypeScript

import { strict as assert } from "assert";
import { newTestUser } from "../clientHelper";
describe("Test: shutdown command", function() {
let client;
this.beforeEach(async function () {
client = await newTestUser(this.config.homeserverUrl, { name: { contains: "shutdown-command" }});
await client.start();
})
this.afterEach(async function () {
await client.stop();
})
it("Mjolnir asks synapse to shut down a channel", async function() {
this.timeout(20000);
const badRoom = await client.createRoom();
await client.joinRoom(this.mjolnir.managementRoomId);
let reply1 = new Promise(async (resolve, reject) => {
const msgid = await client.sendMessage(this.mjolnir.managementRoomId, {msgtype: "m.text", body: `!mjolnir shutdown room ${badRoom} closure test`});
client.on('room.event', (roomId, event) => {
if (
roomId === this.mjolnir.managementRoomId
&& event?.type === "m.reaction"
&& event.sender === this.mjolnir.client.userId
&& event.content?.["m.relates_to"]?.event_id === msgid
) {
resolve(event);
}
});
});
const reply2 = new Promise((resolve, reject) => {
this.mjolnir.client.on('room.event', (roomId, event) => {
if (
roomId !== this.mjolnir.managementRoomId
&& roomId !== badRoom
&& event?.type === "m.room.message"
&& event.sender === this.mjolnir.client.userId
&& event.content?.body === "closure test"
) {
resolve(event);
}
});
});
await reply1
await reply2
await assert.rejects(client.joinRoom(badRoom), (e: any) => {
assert.equal(e.statusCode, 403);
assert.equal(e.body.error, "This room has been blocked on this server");
return true;
});
});
});