Files
Draupnir/apps/draupnir/test/unit/protections/MentionLimitProtectionTest.ts
Gnuxie b63ab3ce89
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 the aliases for the matrix-protection-suite packages. (#1162)
* 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.
2026-07-18 12:12:57 +00:00

67 lines
1.7 KiB
TypeScript

// Copyright 2024 Gnuxie <Gnuxie@protonmail.com>
// Copyright 2024 The Matrix.org Foundation C.I.C.
//
// SPDX-License-Identifier: Apache-2.0
import {
DefaultMixinExtractor,
EventWithMixins,
randomRoomID,
randomUserID,
RoomEvent,
} from "@the-draupnir-project/matrix-protection-suite";
import { isContainingMentionsOverLimit } from "../../../src/protections/MentionLimitProtection";
import expect from "expect";
function messageEvent(content: {
body?: string;
formatted_body?: string;
"m.mentions"?: { user_ids: string[] };
}): EventWithMixins {
return DefaultMixinExtractor.parseEvent({
content,
type: "m.room.message",
sender: randomUserID(),
room_id: randomRoomID([]).toRoomIDOrAlias(),
} as RoomEvent);
}
describe("MentionLimitProtection test", function () {
it("Allows normal events", function () {
expect(
isContainingMentionsOverLimit(
messageEvent({ body: "Hello", formatted_body: "Hello" }),
1,
true
)
).toBe(false);
});
it("Detects mentions in the body", function () {
expect(
isContainingMentionsOverLimit(
messageEvent({ body: "Hello @admin:example.com" }),
0,
true
)
).toBe(true);
});
it("Detects mentions from m.mentions", function () {
expect(
isContainingMentionsOverLimit(
messageEvent({ "m.mentions": { user_ids: ["@admin:example.com"] } }),
0,
true
)
).toBe(true);
});
it("Allows mentions under the limit", function () {
expect(
isContainingMentionsOverLimit(
messageEvent({ "m.mentions": { user_ids: ["@admin:example.com"] } }),
1,
true
)
).toBe(false);
});
});