test: fix so copied object is used instead of original object

This commit is contained in:
P. Reis 2024-04-16 13:41:32 -03:00
parent 3219b53682
commit ed92001b75
1 changed files with 17 additions and 17 deletions

View File

@ -25,20 +25,20 @@ Deno.test('hydrate author', async () => {
await db.event(event0copy); await db.event(event0copy);
await db.event(event1copy); await db.event(event1copy);
assertEquals((event1 as DittoEvent).author, undefined, "Event hasn't been hydrated yet"); assertEquals((event1copy as DittoEvent).author, undefined, "Event hasn't been hydrated yet");
const controller = new AbortController(); const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 1000); const timeoutId = setTimeout(() => controller.abort(), 1000);
await hydrateEvents({ await hydrateEvents({
events: [event1], events: [event1copy],
relations: ['author'], relations: ['author'],
storage: db, storage: db,
signal: controller.signal, signal: controller.signal,
}); });
const expectedEvent = { ...event1, author: event0 }; const expectedEvent = { ...event1copy, author: event0copy };
assertEquals(event1, expectedEvent); assertEquals(event1copy, expectedEvent);
await db.remove([{ kinds: [0, 1] }]); await db.remove([{ kinds: [0, 1] }]);
assertEquals(await db.query([{ kinds: [0, 1] }]), []); assertEquals(await db.query([{ kinds: [0, 1] }]), []);
@ -60,21 +60,21 @@ Deno.test('hydrate repost', async () => {
await db.event(event1repostedCopy); await db.event(event1repostedCopy);
await db.event(event6copy); await db.event(event6copy);
assertEquals((event6 as DittoEvent).author, undefined, "Event hasn't been hydrated author yet"); assertEquals((event6copy as DittoEvent).author, undefined, "Event hasn't been hydrated author yet");
assertEquals((event6 as DittoEvent).repost, undefined, "Event hasn't been hydrated repost yet"); assertEquals((event6copy as DittoEvent).repost, undefined, "Event hasn't been hydrated repost yet");
const controller = new AbortController(); const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 1000); const timeoutId = setTimeout(() => controller.abort(), 1000);
await hydrateEvents({ await hydrateEvents({
events: [event6], events: [event6copy],
relations: ['repost', 'author'], relations: ['repost', 'author'],
storage: db, storage: db,
signal: controller.signal, signal: controller.signal,
}); });
const expectedEvent6 = { ...event6, author: event0madeRepost, repost: { ...event1reposted, author: event0madePost } }; const expectedEvent6 = { ...event6copy, author: event0madeRepostCopy, repost: { ...event1repostedCopy, author: event0madePostCopy } };
assertEquals(event6, expectedEvent6); assertEquals(event6copy, expectedEvent6);
await db.remove([{ kinds: [0, 1, 6] }]); await db.remove([{ kinds: [0, 1, 6] }]);
assertEquals(await db.query([{ kinds: [0, 1, 6] }]), []); assertEquals(await db.query([{ kinds: [0, 1, 6] }]), []);
@ -100,19 +100,19 @@ Deno.test('hydrate quote repost with hydrate author', async () => {
const timeoutId = setTimeout(() => controller.abort(), 1000); const timeoutId = setTimeout(() => controller.abort(), 1000);
await hydrateEvents({ await hydrateEvents({
events: [event1quoteRepost], events: [event1quoteRepostCopy],
relations: ['author', 'quote_repost'], // if author is called first the performance will be better relations: ['author', 'quote_repost'], // if author is called first the performance will be better
storage: db, storage: db,
signal: controller.signal, signal: controller.signal,
}); });
const expectedEvent1quoteRepost = { const expectedEvent1quoteRepost = {
...event1quoteRepost, ...event1quoteRepostCopy,
author: event0madeQuoteRepost, author: event0madeQuoteRepostCopy,
quote_repost: { ...event1willBeQuoteReposted, author: event0 }, quote_repost: { ...event1willBeQuoteRepostedCopy, author: event0copy },
}; };
assertEquals(event1quoteRepost, expectedEvent1quoteRepost); assertEquals(event1quoteRepostCopy, expectedEvent1quoteRepost);
await db.remove([{ kinds: [0, 1] }]); await db.remove([{ kinds: [0, 1] }]);
assertEquals(await db.query([{ kinds: [0, 1] }]), []); assertEquals(await db.query([{ kinds: [0, 1] }]), []);
@ -138,7 +138,7 @@ Deno.test('hydrate quote repost WITHOUT hydrate author', async () => {
const timeoutId = setTimeout(() => controller.abort(), 1000); const timeoutId = setTimeout(() => controller.abort(), 1000);
await hydrateEvents({ await hydrateEvents({
events: [event1quoteRepost, event1willBeQuoteReposted], events: [event1quoteRepostCopy, event1willBeQuoteRepostedCopy],
relations: ['quote_repost'], relations: ['quote_repost'],
storage: db, storage: db,
signal: controller.signal, signal: controller.signal,
@ -146,10 +146,10 @@ Deno.test('hydrate quote repost WITHOUT hydrate author', async () => {
const expectedEvent1quoteRepost = { const expectedEvent1quoteRepost = {
...event1quoteRepost, ...event1quoteRepost,
quote_repost: { ...event1willBeQuoteReposted, author: event0 }, quote_repost: { ...event1willBeQuoteRepostedCopy, author: event0copy },
}; };
assertEquals(event1quoteRepost, expectedEvent1quoteRepost); assertEquals(event1quoteRepostCopy, expectedEvent1quoteRepost);
await db.remove([{ kinds: [0, 1] }]); await db.remove([{ kinds: [0, 1] }]);
assertEquals(await db.query([{ kinds: [0, 1] }]), []); assertEquals(await db.query([{ kinds: [0, 1] }]), []);