Files
Draupnir/test/integration/commands/hijackRoomCommandTest.ts
T
Gnuxie 8973db487b Migrate to eslint-9 flat config, typescript 5, typescript-eslint strictTypeChecked (#476)
* Migrate to eslint-9 strictTypeChecked & typescript 5.

* Update to MPS 0.23.0.

Required for strict type checks.

* Looks like we found a test that was complete garbage, amazing really.

* FIXUP

* Well, the command handler was bugged previously...

The command handler used to always only return the command
without the prefix due to an operator precedence bug.
This meant that when we made the order of operations explicit,
we were now including the prefix of the command in the copy.
So when we parsed arguments the code wasn't expecting the prefix
to be there.

* update to MPS 0.23.1.

MPS 0.23.0 was bugged because we didn't enable
`noUncheckedIndexedAccess` while upgrading to typescript 5.

* Make sure eslint runs on all ts files.

* eslint fixes.

* enable `noUncheckedIndexedAccess` & `exactOptionalPropertyTypes`.

* eslint ignores is clearly not understood by me.

* Update SuperCoolStream for eslint and ts5.

* stricter eslint done i thinks

* Whoops, added on .only somewhere.

* Update MPS.

* fix broken test realted things.

* Well I guess that part of getMessagesByUserIn was part of the interface.

* Fix redactionCommandTest.

* Account for escapeHTML in tests.

* Fix tests.

* stuff not matching with .editorconfig fixes.

* Fix appservice webAPI test.

* Update for MPS 0.23.3.
2024-07-22 16:54:04 +01:00

35 lines
2.1 KiB
TypeScript

import { strict as assert } from "assert";
import { newTestUser } from "../clientHelper";
import { getFirstReaction } from "./commandUtils";
import { DraupnirTestContext, draupnirSafeEmitter } from "../mjolnirSetupUtils";
describe("Test: The make admin command", function () {
it('Mjölnir make the bot self room administrator', async function (this: DraupnirTestContext) {
this.timeout(90000);
if (!this.config.admin?.enableMakeRoomAdminCommand) {
this.done();
}
const draupnir = this.draupnir;
if (draupnir === undefined) {
throw new TypeError(`Test didn't setup correctly`);
}
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();
await moderator.joinRoom(draupnir.managementRoomID);
const 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 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(draupnirSafeEmitter(), draupnir.managementRoomID, '✅', async () => {
return await moderator.sendMessage(draupnir.managementRoomID, { msgtype: 'm.text', body: `!draupnir hijack room ${targetRoom} ${draupnir.clientUserID}` });
});
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], undefined, "User A is not supposed to be a room admin.");
} as unknown as Mocha.AsyncFunc);
});