Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy the makeAdminCommandTest #285

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions test/integration/commands/makeAdminCommandTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { strict as assert } from "assert";

import config from "../../../src/config";
import { newTestUser } from "../clientHelper";
import { LogService } from "matrix-bot-sdk";
import { getFirstReaction } from "./commandUtils";

describe("Test: The make admin command", function () {
it('make Mjölnir the room administrator by "hijacking" a room via the Synapse admin API.', async function () {
this.timeout(90000);
if (!config.admin?.enableMakeRoomAdminCommand) {
LogService.warn("makedminCommandTest", `SKIPPING because the make room admin command is disabled`);
this.skip();
}
const mjolnir = config.RUNTIME.client!;
const mjolnirUserId = await mjolnir.getUserId();
const moderator = await newTestUser({ name: { contains: "moderator" } });
const unrelatedUser = await newTestUser({ name: { contains: "new-admin" } });
const unrelatedUserId = await unrelatedUser.getUserId();

await moderator.joinRoom(config.managementRoom);
let targetRoom = await moderator.createRoom({ invite: [mjolnirUserId], preset: "public_chat" });
await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text.', body: `!mjolnir rooms add ${targetRoom}` });

await unrelatedUser.joinRoom(targetRoom);
let powerLevels = await mjolnir.getRoomStateEvent(targetRoom, "m.room.power_levels", "");
assert.notEqual(powerLevels["users"][mjolnirUserId], 100, `Bot should not yet be an admin of ${targetRoom}`);
await getFirstReaction(mjolnir, this.mjolnir.managementRoomId, '✅', async () => {
return await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text', body: `!mjolnir make admin ${targetRoom}` });
});
LogService.debug("makeadminTest", `Making self admin`);

powerLevels = await mjolnir.getRoomStateEvent(targetRoom, "m.room.power_levels", "");
assert.equal(powerLevels["users"][mjolnirUserId], 100, "Bot should be a room admin.");
assert.equal(powerLevels["users"][unrelatedUserId], (0 || undefined), "User A is not supposed to be a room admin.");
});
});
107 changes: 0 additions & 107 deletions test/integration/commands/makedminCommandTest.ts

This file was deleted.

1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"./src/**/*",
"./test/integration/manualLaunchScript.ts",
"./test/integration/roomMembersTest.ts",
"./test/integration/commands/makedminCommandTest.ts",
"./test/integration/banListTest.ts"
]
}