import { test } from 'node:test'; import assert from 'node:assert/strict'; import { dedupePolicyEntries, recommendationLabel } from './policyEntries'; const e = (entity: string, recommendation: string, stateKey = entity) => ({ entity, reason: 'spam waves', recommendation, stateKey, }); test('dedupePolicyEntries: a stable rule and its legacy twin show once (#321)', () => { const out = dedupePolicyEntries([ e('@spammer:evil.example', 'm.ban'), e('@spammer:evil.example', 'org.matrix.mjolnir.ban'), e('@*:spam.example', 'm.ban'), ]); assert.deepEqual( out.map((x) => x.entity), ['@spammer:evil.example', '@*:spam.example'], ); }); test('dedupePolicyEntries: different recommendations stay separate', () => { assert.equal(dedupePolicyEntries([e('@a:x', 'm.ban'), e('@a:x', 'org.example.mute')]).length, 2); }); test('recommendationLabel', () => { assert.equal(recommendationLabel('m.ban'), 'Ban'); assert.equal(recommendationLabel('org.matrix.mjolnir.ban'), 'Ban'); assert.equal(recommendationLabel('org.example.mute'), 'org.example.mute'); });