Files
Draupnir/test/integration/utilsTest.ts
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

43 lines
2.0 KiB
TypeScript

import { strict as assert } from "assert";
import { LogLevel } from "matrix-bot-sdk";
import { DraupnirTestContext, draupnirClient } from "./mjolnirSetupUtils";
import { NoticeMessageContent, RoomEvent, Value } from "matrix-protection-suite";
describe("Test: utils", function() {
it("replaceRoomIdsWithPills correctly turns a room ID in to a pill", async function(this: DraupnirTestContext) {
const managementRoomAlias = this.config.managementRoom;
const draupnir = this.draupnir;
const draupnirMatrixClient = draupnirClient();
if (draupnir === undefined || draupnirMatrixClient === null) {
throw new TypeError(`Setup code is broken`);
}
const managementRoomOutput = draupnir.managementRoomOutput;
await draupnir.client.sendStateEvent(
draupnir.managementRoomID,
"m.room.canonical_alias",
"",
{ alias: managementRoomAlias }
);
const message: RoomEvent = await new Promise(resolve => {
draupnirMatrixClient.on('room.message', (roomId, event) => {
if (roomId === draupnir.managementRoomID) {
if (event.content?.body?.startsWith("it's")) {
resolve(event);
}
}
})
void managementRoomOutput.logMessage(LogLevel.INFO, 'replaceRoomIdsWithPills test',
`it's fun here in ${draupnir.managementRoomID}`,
[draupnir.managementRoomID, "!myfaketestid:example.com"]);
});
if (!Value.Check(NoticeMessageContent, message.content)) {
throw new TypeError(`This test is written with the expectation logMessage will send a notice`);
}
assert.equal(
message.content.formatted_body,
`it&#39;s fun here in <a href="https://matrix.to/#/${encodeURIComponent(managementRoomAlias)}">${managementRoomAlias}</a>`
);
} as unknown as Mocha.AsyncFunc);
});