Add test for antiDuplicationPolicy

This commit is contained in:
Alex Gleason 2023-03-26 16:19:33 -05:00
parent b641b03726
commit a809da4249
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
4 changed files with 31 additions and 2 deletions

View File

@ -16,4 +16,4 @@ lint:
test:
stage: test
script: deno test
script: deno task test

View File

@ -1,5 +1,6 @@
{
"tasks": {
"test": "deno test --allow-read --allow-write"
},
"lint": {
"files": {

View File

@ -1,3 +1,3 @@
export { readLines } from 'https://deno.land/std@0.181.0/io/mod.ts';
export { assert } from 'https://deno.land/std@0.181.0/testing/asserts.ts';
export { assert, assertEquals } from 'https://deno.land/std@0.181.0/testing/asserts.ts';
export { Keydb } from 'https://deno.land/x/keydb@1.0.0/sqlite.ts';

View File

@ -0,0 +1,28 @@
import { assertEquals } from '../deps.ts';
import { buildEvent, buildInputMessage } from '../test.ts';
import antiDuplicationPolicy from './anti-duplication-policy.ts';
Deno.test({
name: 'blocks events that post the same content too quickly',
fn: async () => {
const content = 'Spicy peppermint apricot mediterranean ginger carrot spiced juice edamame hummus';
const opts = {
databaseUrl: `sqlite:///tmp/${crypto.randomUUID()}.sqlite3`,
};
const msg1 = buildInputMessage({ event: buildEvent({ content }) });
assertEquals((await antiDuplicationPolicy(msg1, opts)).action, 'accept');
assertEquals((await antiDuplicationPolicy(msg1, opts)).action, 'shadowReject');
assertEquals((await antiDuplicationPolicy(msg1, opts)).action, 'shadowReject');
const msg2 = buildInputMessage({ event: buildEvent({ content: 'a' }) });
assertEquals((await antiDuplicationPolicy(msg2, opts)).action, 'accept');
assertEquals((await antiDuplicationPolicy(msg2, opts)).action, 'accept');
assertEquals((await antiDuplicationPolicy(msg2, opts)).action, 'accept');
},
sanitizeResources: false,
});