diff --git a/test/integration/commands/roomsTest.ts b/test/integration/commands/roomsTest.ts index bc8ab5e1..aadf2ae7 100644 --- a/test/integration/commands/roomsTest.ts +++ b/test/integration/commands/roomsTest.ts @@ -1,39 +1,44 @@ import { strict as assert } from "assert"; import { newTestUser } from "../clientHelper"; import { getFirstReaction, getFirstReply } from "./commandUtils"; +import { DraupnirTestContext } from "../mjolnirSetupUtils"; +import { MatrixClient } from 'matrix-bot-sdk'; + +interface RoomsTestContext extends DraupnirTestContext { + moderator?: MatrixClient; +} describe("Test: The rooms commands", 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('Mjolnir can protect a room, show that it is protected and then stop protecting the room.', async function() { + it('Mjolnir can protect a room, show that it is protected and then stop protecting the room.', async function(this: RoomsTestContext) { // Create a few users and a room. - const mjolnir = this.mjolnir.client; - let mjolnirUserId = await mjolnir.getUserId(); + const draupnir = this.draupnir!; let moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } }); this.moderator = moderator; await moderator.joinRoom(this.config.managementRoom); - let targetRoom = await moderator.createRoom({ invite: [mjolnirUserId]}); - await moderator.setUserPowerLevel(mjolnirUserId, targetRoom, 100); + let targetRoom = await moderator.createRoom({ invite: [draupnir.clientUserID]}); + await moderator.setUserPowerLevel(draupnir.clientUserID, targetRoom, 100); try { await moderator.start(); - await getFirstReaction(moderator, this.mjolnir.managementRoomId, '✅', async () => { - return await moderator.sendMessage(this.mjolnir.managementRoomId, {msgtype: 'm.text', body: `!mjolnir rooms add ${targetRoom}`}); + await getFirstReaction(moderator, draupnir.managementRoomID, '✅', async () => { + return await moderator.sendMessage(draupnir.managementRoomID, {msgtype: 'm.text', body: `!draupnir rooms add ${targetRoom}`}); }); - let protectedRoomsMessage = await getFirstReply(moderator, this.mjolnir.managementRoomId, async () => { - return await moderator.sendMessage(this.mjolnir.managementRoomId, {msgtype: 'm.text', body: `!mjolnir rooms`}); + let protectedRoomsMessage = await getFirstReply(moderator, draupnir.managementRoomID, async () => { + return await moderator.sendMessage(draupnir.managementRoomID, {msgtype: 'm.text', body: `!draupnir rooms`}); }) - assert.equal(protectedRoomsMessage['content']?.['body']?.includes('1'), true, "There should be one protected room"); - await getFirstReaction(moderator, this.mjolnir.managementRoomId, '✅', async () => { - return await moderator.sendMessage(this.mjolnir.managementRoomId, {msgtype: 'm.text', body: `!mjolnir rooms remove ${targetRoom}`}); + assert.equal(protectedRoomsMessage['content']?.['body']?.includes('2'), true, "There should be two protected rooms (including the management room)"); + await getFirstReaction(moderator, draupnir.managementRoomID, '✅', async () => { + return await moderator.sendMessage(draupnir.managementRoomID, {msgtype: 'm.text', body: `!draupnir rooms remove ${targetRoom}`}); }); - protectedRoomsMessage = await getFirstReply(moderator, this.mjolnir.managementRoomId, async () => { - return await moderator.sendMessage(this.mjolnir.managementRoomId, {msgtype: 'm.text', body: `!mjolnir rooms`}); + protectedRoomsMessage = await getFirstReply(moderator, draupnir.managementRoomID, async () => { + return await moderator.sendMessage(draupnir.managementRoomID, {msgtype: 'm.text', body: `!draupnir rooms`}); }) - assert.equal(protectedRoomsMessage['content']?.['body']?.includes('0'), true, "There room should no longer be protected"); + assert.equal(protectedRoomsMessage['content']?.['body']?.includes('1'), true, "Only the management room should be protected."); } finally { moderator.stop(); } - }) + } as unknown as Mocha.AsyncFunc) })