Files
Draupnir/test/unit/protections/MentionLimitProtectionTest.ts
T
Gnuxie 32124edc5d Improve and stabalise the mention limit protection. (#844)
- Send a warning message when the event gets removed.
- Ban on the second infraction.
- Make it an option as to whether the message gets split.
- The config file won't work anymore can't fix that because wuh we can't have both as the source of truth........ unless we differentiate based on the timestamp but that requires infrastructure changes.
2025-05-13 21:47:53 +01:00

56 lines
1.4 KiB
TypeScript

// Copyright 2024 Gnuxie <Gnuxie@protonmail.com>
// Copyright 2024 The Matrix.org Foundation C.I.C.
//
// SPDX-License-Identifier: Apache-2.0
import { RoomEvent } from "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[] };
}): RoomEvent {
return { content } 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);
});
});