From 7dd63787178c16957f4cba5143c83567324b55f2 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Thu, 18 Apr 2024 11:30:49 -0300 Subject: [PATCH] test: improv code coverage in quote repost hydration --- src/storages/hydrate.test.ts | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/storages/hydrate.test.ts b/src/storages/hydrate.test.ts index 550693f..0c36717 100644 --- a/src/storages/hydrate.test.ts +++ b/src/storages/hydrate.test.ts @@ -124,6 +124,44 @@ Deno.test('hydrate quote repost with hydrate author', async () => { clearTimeout(timeoutId); }); +Deno.test('hydrate quote repost and original post with hydrate author ', async () => { + const db = new NCache({ max: 100 }); + + const event0madeQuoteRepostCopy = structuredClone(event0madeQuoteRepost); + const event0copy = structuredClone(event0); + const event1quoteRepostCopy = structuredClone(event1quoteRepost); + const event1willBeQuoteRepostedCopy = structuredClone(event1willBeQuoteReposted); + + // Save events to database + await db.event(event0madeQuoteRepostCopy); + await db.event(event0copy); + await db.event(event1quoteRepostCopy); + await db.event(event1willBeQuoteRepostedCopy); + + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), 1000); + + await hydrateEvents({ + events: [event1quoteRepostCopy, event1willBeQuoteRepostedCopy], + relations: ['author', 'quote_repost'], // if author is called first the performance will be better + storage: db, + signal: controller.signal, + }); + + const expectedEvent1quoteRepost = { + ...event1quoteRepostCopy, + author: event0madeQuoteRepostCopy, + quote_repost: { ...event1willBeQuoteRepostedCopy, author: event0copy }, + }; + + assertEquals(event1quoteRepostCopy, expectedEvent1quoteRepost); + + await db.remove([{ kinds: [0, 1] }]); + assertEquals(await db.query([{ kinds: [0, 1] }]), []); + + clearTimeout(timeoutId); +}); + Deno.test('hydrate quote repost WITHOUT hydrate author', async () => { const db = new NCache({ max: 100 });