strfry-policies/src/policies/keyword-policy.test.ts
2023-03-29 23:51:15 -05:00

18 lines
772 B
TypeScript

import { assertEquals } from '../deps.ts';
import { buildEvent, buildInputMessage } from '../test.ts';
import keywordPolicy from './keyword-policy.ts';
Deno.test('blocks banned pubkeys', async () => {
const words = ['https://t.me/spam', 'hello world'];
const msg0 = buildInputMessage();
const msg1 = buildInputMessage({ event: buildEvent({ content: '🔥🔥🔥 https://t.me/spam 我想死' }) });
const msg2 = buildInputMessage({ event: buildEvent({ content: 'hElLo wOrLd!' }) });
assertEquals((await keywordPolicy(msg0, words)).action, 'accept');
assertEquals((await keywordPolicy(msg1, words)).action, 'reject');
assertEquals((await keywordPolicy(msg1, [])).action, 'accept');
assertEquals((await keywordPolicy(msg2, words)).action, 'reject');
});