Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Oct 22, 2024
1 parent 1b43be9 commit 2777b78
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions test/integration/commands/shutdownCommandTest.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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 &&
Expand All @@ -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" });
});
});

0 comments on commit 2777b78

Please sign in to comment.