From 31fd761278dc8f79b0930ccc49fea3fdaa487729 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 26 Mar 2023 16:29:35 -0500 Subject: [PATCH] Add pipeline test --- src/pipeline.test.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/pipeline.test.ts diff --git a/src/pipeline.test.ts b/src/pipeline.test.ts new file mode 100644 index 0000000..f046ef2 --- /dev/null +++ b/src/pipeline.test.ts @@ -0,0 +1,42 @@ +import { assertEquals } from './deps.ts'; + +import pipeline from './pipeline.ts'; +import noopPolicy from './policies/noop-policy.ts'; +import readOnlyPolicy from './policies/read-only-policy.ts'; +import { buildInputMessage } from './test.ts'; + +Deno.test('passes events through multiple policies', async () => { + const msg = buildInputMessage(); + + const result = await pipeline(msg, [ + noopPolicy, + readOnlyPolicy, + ]); + + assertEquals(result.action, 'reject'); + assertEquals(result.msg, 'The relay is read-only.'); +}); + +Deno.test('short-circuits on the first reject', async () => { + const msg = buildInputMessage(); + + const result = await pipeline(msg, [ + readOnlyPolicy, + noopPolicy, + ]); + + assertEquals(result.action, 'reject'); + assertEquals(result.msg, 'The relay is read-only.'); +}); + +Deno.test('accepts when all policies accept', async () => { + const msg = buildInputMessage(); + + const result = await pipeline(msg, [ + noopPolicy, + noopPolicy, + noopPolicy, + ]); + + assertEquals(result.action, 'accept'); +});