mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-04-05 05:45:44 +00:00
Fix hijack room command test.
This commit is contained in:
@@ -1,35 +1,31 @@
|
||||
import { strict as assert } from "assert";
|
||||
import { MjolnirTestContext } from "../mjolnirSetupUtils";
|
||||
import { newTestUser } from "../clientHelper";
|
||||
import { getFirstReaction } from "./commandUtils";
|
||||
import { DraupnirTestContext, draupnirClient } from "../mjolnirSetupUtils";
|
||||
|
||||
describe("Test: The make admin command", function () {
|
||||
it('Mjölnir make the bot self room administrator', async function (this: MjolnirTestContext) {
|
||||
it('Mjölnir make the bot self room administrator', async function (this: DraupnirTestContext) {
|
||||
this.timeout(90000);
|
||||
if (!this.config.admin?.enableMakeRoomAdminCommand) {
|
||||
this.done();
|
||||
}
|
||||
const mjolnir = this.mjolnir!;
|
||||
const mjolnirUserId = await mjolnir.client.getUserId();
|
||||
const draupnir = this.draupnir!;
|
||||
const moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
|
||||
const userA = await newTestUser(this.config.homeserverUrl, { name: { contains: "a" } });
|
||||
const userAId = await userA.getUserId();
|
||||
this.moderator = moderator;
|
||||
this.userA = userA;
|
||||
|
||||
await moderator.joinRoom(this.config.managementRoom);
|
||||
let targetRoom = await moderator.createRoom({ invite: [mjolnirUserId], preset: "public_chat" });
|
||||
await moderator.sendMessage(mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir rooms add ${targetRoom}` });
|
||||
await moderator.joinRoom(draupnir.managementRoomID);
|
||||
let targetRoom = await moderator.createRoom({ invite: [draupnir.clientUserID], preset: "public_chat" });
|
||||
await moderator.sendMessage(draupnir.managementRoomID, { msgtype: 'm.text.', body: `!draupnir rooms add ${targetRoom}` });
|
||||
await userA.joinRoom(targetRoom);
|
||||
const powerLevelsBefore = await mjolnir.client.getRoomStateEvent(targetRoom, "m.room.power_levels", "");
|
||||
await mjolnir.matrixEmitter.start();
|
||||
assert.notEqual(powerLevelsBefore["users"][mjolnirUserId], 100, `Bot should not yet be an admin of ${targetRoom}`);
|
||||
await getFirstReaction(mjolnir.matrixEmitter, mjolnir.managementRoomId, '✅', async () => {
|
||||
return await moderator.sendMessage(mjolnir.managementRoomId, { msgtype: 'm.text', body: `!mjolnir hijack room ${targetRoom} ${mjolnirUserId}` });
|
||||
const powerLevelsBefore = await moderator.getRoomStateEvent(targetRoom, "m.room.power_levels", "");
|
||||
assert.notEqual(powerLevelsBefore["users"][draupnir.clientUserID], 100, `Bot should not yet be an admin of ${targetRoom}`);
|
||||
await getFirstReaction(draupnirClient()!, draupnir.managementRoomID, '✅', async () => {
|
||||
return await moderator.sendMessage(draupnir.managementRoomID, { msgtype: 'm.text', body: `!draupnir hijack room ${targetRoom} ${draupnir.clientUserID}` });
|
||||
});
|
||||
|
||||
const powerLevelsAfter = await mjolnir.client.getRoomStateEvent(targetRoom, "m.room.power_levels", "");
|
||||
assert.equal(powerLevelsAfter["users"][mjolnirUserId], 100, "Bot should be a room admin.");
|
||||
const powerLevelsAfter = await moderator.getRoomStateEvent(targetRoom, "m.room.power_levels", "");
|
||||
assert.equal(powerLevelsAfter["users"][draupnir.clientUserID], 100, "Bot should be a room admin.");
|
||||
assert.equal(powerLevelsAfter["users"][userAId], (0 || undefined), "User A is not supposed to be a room admin.");
|
||||
});
|
||||
} as unknown as Mocha.AsyncFunc);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user