From 2777b780e1402a06539cc2efc41a2688b55b2e5e Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Tue, 22 Oct 2024 14:07:59 -0700 Subject: [PATCH] test --- .../commands/shutdownCommandTest.ts | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/test/integration/commands/shutdownCommandTest.ts b/test/integration/commands/shutdownCommandTest.ts index 7c79234f..cdb661f7 100644 --- a/test/integration/commands/shutdownCommandTest.ts +++ b/test/integration/commands/shutdownCommandTest.ts @@ -1,9 +1,11 @@ import { strict as assert } from "assert"; import { newTestUser } from "../clientHelper"; +import { getFirstReaction } from "./commandUtils"; +import { MatrixClient } from "@vector-im/matrix-bot-sdk"; describe("Test: shutdown command", function () { - let client; + let client: MatrixClient; this.beforeEach(async function () { client = await newTestUser(this.config.homeserverUrl, { name: { contains: "shutdown-command" } }); await client.start(); @@ -34,7 +36,7 @@ describe("Test: shutdown command", function () { }); const reply2 = new Promise((resolve, reject) => { - this.mjolnir.client.on("room.event", (roomId, event) => { + this.mjolnir.client.on("room.event", (roomId: string, event: any) => { if ( roomId !== this.mjolnir.managementRoomId && roomId !== badRoom && @@ -54,4 +56,42 @@ describe("Test: shutdown command", function () { return e.message.endsWith('{"errcode":"M_UNKNOWN","error":"This room has been blocked on this server"}'); }); }); + it("Mjolnir will not shutdown a room it is protecting.", async function () { + this.timeout(20000); + const targetRoom = await client.createRoom({ preset: "public_chat" }); + await client.joinRoom(this.mjolnir.managementRoomId); + const otherUser = await newTestUser(this.config.homeserverUrl, { + name: { contains: "shutdown-command-extra" }, + }); + + await getFirstReaction(client, this.mjolnir.managementRoomId, "✅", async () => { + return await client.sendMessage(this.mjolnir.managementRoomId, { + msgtype: "m.text", + body: `!mjolnir rooms add ${targetRoom}`, + }); + }); + + await client.sendMessage(this.mjolnir.managementRoomId, { + msgtype: "m.text", + body: `!mjolnir shutdown room ${targetRoom}`, + }); + + let reply = new Promise((resolve, reject) => { + client.on("room.message", (roomId: string, event: any) => { + console.log(JSON.stringify(event)); + if ( + roomId === this.mjolnir.managementRoomId && + event.content?.body.includes( + "You are attempting to shutdown a room that mjolnir currently protects, aborting", + ) + ) { + resolve(event); + } + }); + }); + await reply; + // room should not be shutdown and available to join + const joined = await otherUser.joinRoom(targetRoom); + await otherUser.sendMessage(joined, { msgtype: "m.text", body: "it's fine to interact with this room" }); + }); });