Add test for antiDuplicationPolicy
This commit is contained in:
parent
b641b03726
commit
a809da4249
@ -16,4 +16,4 @@ lint:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
stage: test
|
stage: test
|
||||||
script: deno test
|
script: deno task test
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"tasks": {
|
"tasks": {
|
||||||
|
"test": "deno test --allow-read --allow-write"
|
||||||
},
|
},
|
||||||
"lint": {
|
"lint": {
|
||||||
"files": {
|
"files": {
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
export { readLines } from 'https://deno.land/std@0.181.0/io/mod.ts';
|
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';
|
export { Keydb } from 'https://deno.land/x/keydb@1.0.0/sqlite.ts';
|
||||||
|
28
src/policies/anti-duplication-policy.test.ts
Normal file
28
src/policies/anti-duplication-policy.test.ts
Normal 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,
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user