test: rough adapt tests for new performance hydratation
This commit is contained in:
parent
c7b84e5438
commit
7a12e5ec7b
|
@ -6,16 +6,24 @@ 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 event0madeRepostWithQuoteRepost from '~/fixtures/events/event-0-makes-repost-with-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 event1futureIsMine from '~/fixtures/events/event-1-will-be-reposted-with-quote-repost.json' with {
|
||||
type: 'json',
|
||||
};
|
||||
import event1quoteRepostLatin from '~/fixtures/events/event-1-quote-repost-will-be-reposted.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 event6ofQuoteRepost from '~/fixtures/events/event-6-of-quote-repost.json' with { type: 'json' };
|
||||
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||
|
||||
Deno.test('hydrate author', async () => {
|
||||
Deno.test('hydrateEvents(): author --- WITHOUT stats', async () => {
|
||||
const db = new NCache({ max: 100 });
|
||||
|
||||
const event0copy = structuredClone(event0);
|
||||
|
@ -32,7 +40,6 @@ Deno.test('hydrate author', async () => {
|
|||
|
||||
await hydrateEvents({
|
||||
events: [event1copy],
|
||||
relations: ['author'],
|
||||
storage: db,
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
@ -46,7 +53,7 @@ Deno.test('hydrate author', async () => {
|
|||
clearTimeout(timeoutId);
|
||||
});
|
||||
|
||||
Deno.test('hydrate repost', async () => {
|
||||
Deno.test('hydrateEvents(): repost --- WITHOUT stats', async () => {
|
||||
const db = new NCache({ max: 100 });
|
||||
|
||||
const event0madePostCopy = structuredClone(event0madePost);
|
||||
|
@ -68,7 +75,6 @@ Deno.test('hydrate repost', async () => {
|
|||
|
||||
await hydrateEvents({
|
||||
events: [event6copy],
|
||||
relations: ['repost', 'author'],
|
||||
storage: db,
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
@ -86,7 +92,7 @@ Deno.test('hydrate repost', async () => {
|
|||
clearTimeout(timeoutId);
|
||||
});
|
||||
|
||||
Deno.test('hydrate quote repost with hydrate author', async () => {
|
||||
Deno.test('hydrateEvents(): quote repost --- WITHOUT stats', async () => {
|
||||
const db = new NCache({ max: 100 });
|
||||
|
||||
const event0madeQuoteRepostCopy = structuredClone(event0madeQuoteRepost);
|
||||
|
@ -105,7 +111,6 @@ Deno.test('hydrate quote repost with hydrate author', async () => {
|
|||
|
||||
await hydrateEvents({
|
||||
events: [event1quoteRepostCopy],
|
||||
relations: ['author', 'quote_repost'], // if author is called first the performance will be better
|
||||
storage: db,
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
@ -124,40 +129,41 @@ Deno.test('hydrate quote repost with hydrate author', async () => {
|
|||
clearTimeout(timeoutId);
|
||||
});
|
||||
|
||||
Deno.test('hydrate quote repost and original post with hydrate author ', async () => {
|
||||
Deno.test('hydrateEvents(): repost of quote repost --- WITHOUT stats', async () => {
|
||||
const db = new NCache({ max: 100 });
|
||||
|
||||
const event0madeQuoteRepostCopy = structuredClone(event0madeQuoteRepost);
|
||||
const event0copy = structuredClone(event0);
|
||||
const event1quoteRepostCopy = structuredClone(event1quoteRepost);
|
||||
const event1willBeQuoteRepostedCopy = structuredClone(event1willBeQuoteReposted);
|
||||
const event0copy = structuredClone(event0madeRepostWithQuoteRepost);
|
||||
const event1copy = structuredClone(event1futureIsMine);
|
||||
const event1quoteCopy = structuredClone(event1quoteRepostLatin);
|
||||
const event6copy = structuredClone(event6ofQuoteRepost);
|
||||
|
||||
// Save events to database
|
||||
await db.event(event0madeQuoteRepostCopy);
|
||||
await db.event(event0copy);
|
||||
await db.event(event1quoteRepostCopy);
|
||||
await db.event(event1willBeQuoteRepostedCopy);
|
||||
await db.event(event1copy);
|
||||
await db.event(event1quoteCopy);
|
||||
await db.event(event6copy);
|
||||
|
||||
assertEquals((event6copy as DittoEvent).author, undefined, "Event hasn't been hydrated author yet");
|
||||
assertEquals((event6copy as DittoEvent).repost, undefined, "Event hasn't been hydrated repost yet");
|
||||
|
||||
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
|
||||
events: [event6copy],
|
||||
storage: db,
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
||||
const expectedEvent1quoteRepost = {
|
||||
...event1quoteRepostCopy,
|
||||
author: event0madeQuoteRepostCopy,
|
||||
quote_repost: { ...event1willBeQuoteRepostedCopy, author: event0copy },
|
||||
const expectedEvent6 = {
|
||||
...event6copy,
|
||||
author: event0copy,
|
||||
repost: { ...event1quoteCopy, author: event0copy, quote_repost: { author: event0copy, ...event1copy } },
|
||||
};
|
||||
assertEquals(event6copy, expectedEvent6);
|
||||
|
||||
assertEquals(event1quoteRepostCopy, expectedEvent1quoteRepost);
|
||||
|
||||
await db.remove([{ kinds: [0, 1] }]);
|
||||
assertEquals(await db.query([{ kinds: [0, 1] }]), []);
|
||||
await db.remove([{ kinds: [0, 1, 6] }]);
|
||||
assertEquals(await db.query([{ kinds: [0, 1, 6] }]), []);
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue