mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-08-28 13:24:04 +00:00
Docker Hub - Develop / docker-latest (push) Canceled after 0s
GHCR - Development Branches / ghcr-publish (push) Canceled after 0s
Tests / Build & Lint (push) Canceled after 0s
Tests / Unit tests (push) Canceled after 0s
Tests / Integration tests (push) Canceled after 0s
Tests / Application Service Integration tests (push) Canceled after 0s
Validate Docker Build / validate-docker-build (push) Canceled after 0s
* Remove old matrix-protection-suite package aliases. This was leading to issues with monorepo package management. https://github.com/the-draupnir-project/Draupnir/issues/1124 * Fix badly imported symbols from packages that already export them. * Cleanup build command arguments. There was a deprecation warning for short workspaces flag.
68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
// Copyright 2022 - 2024 Gnuxie <Gnuxie@protonmail.com>
|
|
// Copyright 2021 - 2022 The Matrix.org Foundation C.I.C.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
// SPDX-FileAttributionText: <text>
|
|
// This modified file incorporates work from mjolnir
|
|
// https://github.com/matrix-org/mjolnir
|
|
// </text>
|
|
|
|
import { strict as assert } from "assert";
|
|
import { LogLevel } from "@vector-im/matrix-bot-sdk";
|
|
import { DraupnirTestContext, draupnirSafeEmitter } from "./mjolnirSetupUtils";
|
|
import {
|
|
NoticeMessageContent,
|
|
RoomEvent,
|
|
Value,
|
|
} from "@the-draupnir-project/matrix-protection-suite";
|
|
|
|
describe("Test: utils", function () {
|
|
it(
|
|
"replaceRoomIdsWithPills correctly turns a room ID in to a pill",
|
|
async function (this: DraupnirTestContext) {
|
|
const managementRoomAlias = "#moderators:localhost:9999";
|
|
const draupnir = this.draupnir;
|
|
const draupnirMatrixClient = draupnirSafeEmitter();
|
|
if (draupnir === undefined) {
|
|
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 &&
|
|
Value.Check(NoticeMessageContent, event.content)
|
|
) {
|
|
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's fun here in <a href="https://matrix.to/#/${encodeURIComponent(managementRoomAlias)}">${managementRoomAlias}</a>`
|
|
);
|
|
} as unknown as Mocha.AsyncFunc
|
|
);
|
|
});
|