2022-02-02 12:35:02 -05:00
|
|
|
import { strict as assert } from "assert";
|
2022-09-29 09:49:09 -04:00
|
|
|
import { LogLevel } from "matrix-bot-sdk";
|
|
|
|
import ManagementRoomOutput from "../../src/ManagementRoomOutput";
|
2022-02-02 12:35:02 -05:00
|
|
|
|
|
|
|
describe("Test: utils", function() {
|
|
|
|
it("replaceRoomIdsWithPills correctly turns a room ID in to a pill", async function() {
|
2022-08-16 10:51:18 -04:00
|
|
|
const managementRoomAlias = this.config.managementRoom;
|
2022-09-29 09:49:09 -04:00
|
|
|
const managementRoomOutput: ManagementRoomOutput = this.mjolnir.managementRoomOutput;
|
2022-02-02 12:35:02 -05:00
|
|
|
await this.mjolnir.client.sendStateEvent(
|
|
|
|
this.mjolnir.managementRoomId,
|
|
|
|
"m.room.canonical_alias",
|
|
|
|
"",
|
2022-08-16 10:51:18 -04:00
|
|
|
{ alias: managementRoomAlias }
|
2022-02-02 12:35:02 -05:00
|
|
|
);
|
|
|
|
|
2022-09-29 09:49:09 -04:00
|
|
|
const message: any = await new Promise(async resolve => {
|
|
|
|
this.mjolnir.client.on('room.message', (roomId, event) => {
|
|
|
|
if (roomId === this.mjolnir.managementRoomId) {
|
|
|
|
if (event.content?.body?.startsWith("it's")) {
|
|
|
|
resolve(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
await managementRoomOutput.logMessage(LogLevel.INFO, 'replaceRoomIdsWithPills test',
|
|
|
|
`it's fun here in ${this.mjolnir.managementRoomId}`,
|
|
|
|
[this.mjolnir.managementRoomId, "!myfaketestid:example.com"]);
|
|
|
|
});
|
2022-02-02 12:35:02 -05:00
|
|
|
assert.equal(
|
2022-09-29 09:49:09 -04:00
|
|
|
message.content.formatted_body,
|
2022-08-18 04:37:30 -04:00
|
|
|
`it's fun here in <a href="https://matrix.to/#/${managementRoomAlias}">${managementRoomAlias}</a>`
|
2022-02-02 12:35:02 -05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|