mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
test: add test for hydrate repost of quote repost
This commit is contained in:
parent
2c01234263
commit
621f0b2850
5 changed files with 98 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"id": "4acbf01269a2b09aaa4559b6d950ceffe37985dc3eb56c3d1bb3200ca93fae3d",
|
||||
"pubkey": "2894578b2c8570825f48dc647e746e690f83f92d19446b3051f59cd0196a7991",
|
||||
"created_at": 1713452168,
|
||||
"kind": 0,
|
||||
"tags": [],
|
||||
"content": "{\"name\":\"me\",\"about\":\"\",\"nip05\":\"\"}",
|
||||
"sig": "373ca965fc3772804cf448db8da3add6f59653cb1ba8ba89b8d8fc88e4ed326b446e2641ed675dcaab886eb2678cca5293c6312e03ed9e73ccebca14ef47eaaa"
|
||||
}
|
||||
14
fixtures/events/event-1-quote-repost-will-be-reposted.json
Normal file
14
fixtures/events/event-1-quote-repost-will-be-reposted.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"id": "00b325bba6de17030091558f439d41d4c08b82e60fbcaee3e0331c4c690ef205",
|
||||
"pubkey": "2894578b2c8570825f48dc647e746e690f83f92d19446b3051f59cd0196a7991",
|
||||
"created_at": 1713735562,
|
||||
"kind": 1,
|
||||
"tags": [
|
||||
[
|
||||
"q",
|
||||
"f7b82508931bbeeadb901931e3dea8c4f96f0f9e353ba6cf1ec3a93eb8ad7e05"
|
||||
]
|
||||
],
|
||||
"content": "Deus futurus est deus aquae deiectus!",
|
||||
"sig": "72d8365f3c6b6de89fdfd005798c242629145fdc97bfc25e57bb78a4444c2a297bf41a47d7d0e2ee819d77f73fa3fcfcc4b455928ede7fca715e261c567b0b3b"
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"id": "f7b82508931bbeeadb901931e3dea8c4f96f0f9e353ba6cf1ec3a93eb8ad7e05",
|
||||
"pubkey": "2894578b2c8570825f48dc647e746e690f83f92d19446b3051f59cd0196a7991",
|
||||
"created_at": 1713735505,
|
||||
"kind": 1,
|
||||
"tags": [],
|
||||
"content": "The present is theirs, the future, for which I really worked, is mine.",
|
||||
"sig": "b27fff3ec821e529e74ceede28ecf368682677de1aa2cc2cc65083b8f4a789f53e6a5da899cb0f03e4e6a3555a0fe4421971c427c5c9dd50758127c4da3e9405"
|
||||
}
|
||||
18
fixtures/events/event-6-of-quote-repost.json
Normal file
18
fixtures/events/event-6-of-quote-repost.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"id": "04ee8a34c398ef20bdb56064979aff879f81b6b746232811845eca872e0ebe8d",
|
||||
"pubkey": "2894578b2c8570825f48dc647e746e690f83f92d19446b3051f59cd0196a7991",
|
||||
"created_at": 1713735600,
|
||||
"kind": 6,
|
||||
"tags": [
|
||||
[
|
||||
"e",
|
||||
"00b325bba6de17030091558f439d41d4c08b82e60fbcaee3e0331c4c690ef205"
|
||||
],
|
||||
[
|
||||
"p",
|
||||
"2894578b2c8570825f48dc647e746e690f83f92d19446b3051f59cd0196a7991"
|
||||
]
|
||||
],
|
||||
"content": "",
|
||||
"sig": "061b741a8d399db4c1151ed003a76afcf04cac25b98f2df4d4b6467ea9e0dcb54de9d5a6f959ef86b82e8c6e547a87596aecb904cf5fa99e7f8b67fefd43c0f6"
|
||||
}
|
||||
|
|
@ -6,13 +6,21 @@ 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 () => {
|
||||
|
|
@ -86,6 +94,46 @@ Deno.test('hydrate repost', async () => {
|
|||
clearTimeout(timeoutId);
|
||||
});
|
||||
|
||||
Deno.test('hydrate repost of quote repost', async () => {
|
||||
const db = new NCache({ max: 100 });
|
||||
|
||||
const event0copy = structuredClone(event0madeRepostWithQuoteRepost);
|
||||
const event1copy = structuredClone(event1futureIsMine);
|
||||
const event1quoteCopy = structuredClone(event1quoteRepostLatin);
|
||||
const event6copy = structuredClone(event6ofQuoteRepost);
|
||||
|
||||
// Save events to database
|
||||
await db.event(event0copy);
|
||||
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: [event6copy],
|
||||
relations: ['repost', 'author'],
|
||||
storage: db,
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
||||
const expectedEvent6 = {
|
||||
...event6copy,
|
||||
author: event0copy,
|
||||
repost: { ...event1quoteCopy, author: event0copy, quote_repost: { author: event0copy, ...event1copy } },
|
||||
};
|
||||
assertEquals(event6copy, expectedEvent6);
|
||||
|
||||
await db.remove([{ kinds: [0, 1, 6] }]);
|
||||
assertEquals(await db.query([{ kinds: [0, 1, 6] }]), []);
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
});
|
||||
|
||||
Deno.test('hydrate quote repost with hydrate author', async () => {
|
||||
const db = new NCache({ max: 100 });
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue