From 3bc3e7675d5d0d9f5748fe62ef409e7bb6b02b3b Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Fri, 19 Jul 2024 17:35:34 -0300 Subject: [PATCH] test: getZapSplits function --- src/utils/zap_split.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/utils/zap_split.test.ts diff --git a/src/utils/zap_split.test.ts b/src/utils/zap_split.test.ts new file mode 100644 index 00000000..a439e3aa --- /dev/null +++ b/src/utils/zap_split.test.ts @@ -0,0 +1,36 @@ +import { assertEquals } from '@std/assert'; +import { generateSecretKey, getPublicKey } from 'nostr-tools'; + +import { genEvent } from '@/test.ts'; +import { getZapSplits } from '@/utils/zap_split.ts'; +import { getTestDB } from '@/test.ts'; + +Deno.test('Get zap splits in DittoZapSplits format', async () => { + const { store } = await getTestDB(); + + const sk = generateSecretKey(); + const pubkey = getPublicKey(sk); + + const event = genEvent({ + kind: 30078, + tags: [ + ['d', 'pub.ditto.zapSplits'], + ['p', '47259076c85f9240e852420d7213c95e95102f1de929fb60f33a2c32570c98c4', '2', 'Patrick developer'], + ['p', '0461fcbecc4c3374439932d6b8f11269ccdb7cc973ad7a50ae362db135a474dd', '3', 'Alex creator of Ditto'], + ], + }, sk); + await store.event(event); + + const eventFromDb = await store.query([{ kinds: [30078], authors: [pubkey] }]); + + assertEquals(eventFromDb.length, 1); + + const zapSplits = await getZapSplits(store, pubkey); + + assertEquals(zapSplits, { + '0461fcbecc4c3374439932d6b8f11269ccdb7cc973ad7a50ae362db135a474dd': ['3', 'Alex creator of Ditto'], + '47259076c85f9240e852420d7213c95e95102f1de929fb60f33a2c32570c98c4': ['2', 'Patrick developer'], + }); + + assertEquals(await getZapSplits(store, 'garbage'), {}); +});