From 4a9232faf727858a1e570c17180ec96b5050a4b9 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Tue, 16 Apr 2024 09:31:03 -0300 Subject: [PATCH] test: add test for hydrate quote repost --- src/storages/hydrate.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/storages/hydrate.test.ts b/src/storages/hydrate.test.ts index 671e357..ab2b41d 100644 --- a/src/storages/hydrate.test.ts +++ b/src/storages/hydrate.test.ts @@ -6,7 +6,12 @@ import { hydrateEvents } from '@/storages/hydrate.ts'; import event0 from '~/fixtures/events/event-0.json' with { type: 'json' }; import event0madePost from '~/fixtures/events/event-0-the-one-who-post-and-users-repost.json' with { type: 'json' }; import event0madeRepost from '~/fixtures/events/event-0-the-one-who-repost.json' with { type: 'json' }; +import event0madeQuoteRepost from '~/fixtures/events/event-0-the-one-who-quote-repost.json' with { type: 'json' }; import event1 from '~/fixtures/events/event-1.json' with { type: 'json' }; +import event1quoteRepost from '~/fixtures/events/event-1-quote-repost.json' with { type: 'json' }; +import event1willBeQuoteReposted from '~/fixtures/events/event-1-that-will-be-quote-reposted.json' with { + type: 'json', +}; import event1reposted from '~/fixtures/events/event-1-reposted.json' with { type: 'json' }; import event6 from '~/fixtures/events/event-6.json' with { type: 'json' }; import { DittoEvent } from '@/interfaces/DittoEvent.ts'; @@ -67,3 +72,34 @@ Deno.test('hydrate repost', async () => { clearTimeout(timeoutId); }); + +Deno.test('hydrate quote repost with hydrate author', async () => { + // Save events to database + await eventsDB.event(event0madeQuoteRepost); + await eventsDB.event(event0); + await eventsDB.event(event1quoteRepost); + await eventsDB.event(event1willBeQuoteReposted); + + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 1000); + + await hydrateEvents({ + events: [event1quoteRepost], + relations: ['author', 'quote_repost'], // if author is called first the performance will be better + storage: eventsDB, + signal: controller.signal, + }); + + const expectedEvent1quoteRepost = { + ...event1quoteRepost, + author: event0madeQuoteRepost, + quote_repost: { ...event1willBeQuoteReposted, author: event0 }, + }; + + assertEquals(event1quoteRepost, expectedEvent1quoteRepost); + + await eventsDB.remove([{ kinds: [0, 1] }]); + assertEquals(await eventsDB.query([{ kinds: [0, 1] }]), []); + + clearTimeout(timeoutId); +});