2022-02-02 17:35:02 +00:00
|
|
|
import { strict as assert } from "assert";
|
|
|
|
|
|
|
|
import { UserID } from "matrix-bot-sdk";
|
|
|
|
import config from "../../src/config";
|
|
|
|
import { replaceRoomIdsWithPills } from "../../src/utils";
|
|
|
|
|
|
|
|
describe("Test: utils", function() {
|
|
|
|
it("replaceRoomIdsWithPills correctly turns a room ID in to a pill", async function() {
|
|
|
|
this.timeout(20000);
|
|
|
|
|
2022-08-16 14:51:18 +00:00
|
|
|
const managementRoomAlias = this.config.managementRoom;
|
|
|
|
|
2022-02-02 17:35:02 +00:00
|
|
|
await this.mjolnir.client.sendStateEvent(
|
|
|
|
this.mjolnir.managementRoomId,
|
|
|
|
"m.room.canonical_alias",
|
|
|
|
"",
|
2022-08-16 14:51:18 +00:00
|
|
|
{ alias: managementRoomAlias }
|
2022-02-02 17:35:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const out = await replaceRoomIdsWithPills(
|
2022-02-15 15:44:41 +00:00
|
|
|
this.mjolnir,
|
2022-02-02 17:35:02 +00:00
|
|
|
`it's fun here in ${this.mjolnir.managementRoomId}`,
|
|
|
|
new Set([this.mjolnir.managementRoomId])
|
|
|
|
);
|
|
|
|
|
|
|
|
const ourHomeserver = new UserID(await this.mjolnir.client.getUserId()).domain;
|
|
|
|
assert.equal(
|
|
|
|
out.formatted_body,
|
2022-08-16 14:51:18 +00:00
|
|
|
`it's fun here in <a href="https://matrix.to/#/${managementRoomAlias}?via=${ourHomeserver}">${managementRoomAlias}</a>`
|
2022-02-02 17:35:02 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|