mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge remote-tracking branch 'origin/main' into push
This commit is contained in:
commit
d9d280e6c1
2 changed files with 24 additions and 1 deletions
|
|
@ -221,3 +221,26 @@ Deno.test("throws a RelayError when querying an event with a large 'kind'", asyn
|
||||||
'kind filter too far into the future',
|
'kind filter too far into the future',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test('NPostgres.query with search', async (t) => {
|
||||||
|
await using db = await createTestDB({ pure: true });
|
||||||
|
const { store } = db;
|
||||||
|
|
||||||
|
const eventA = genEvent({ kind: 1, content: 'Fediverse is vegan', created_at: 0 });
|
||||||
|
const eventB = genEvent({ kind: 1, content: 'Im vegan btw', created_at: 1 });
|
||||||
|
|
||||||
|
await store.event(eventA);
|
||||||
|
await store.event(eventB);
|
||||||
|
|
||||||
|
await t.step('match single event', async () => {
|
||||||
|
assertEquals(await store.query([{ search: 'Fediverse' }]), [eventA]);
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step('match multiple events', async () => {
|
||||||
|
assertEquals(await store.query([{ search: 'vegan' }]), [eventB, eventA]);
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("don't match nonsense queries", async () => {
|
||||||
|
assertEquals(await store.query([{ search: "this shouldn't match" }]), []);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -337,7 +337,7 @@ class EventsDB extends NPostgres {
|
||||||
|
|
||||||
// Re-serialize the search string without the domain key. :facepalm:
|
// Re-serialize the search string without the domain key. :facepalm:
|
||||||
filter.search = tokens
|
filter.search = tokens
|
||||||
.filter((t) => typeof t === 'object' && t.key !== 'domain')
|
.filter((t) => typeof t === 'string' || typeof t === 'object' && t.key !== 'domain')
|
||||||
.map((t) => typeof t === 'object' ? `${t.key}:${t.value}` : t)
|
.map((t) => typeof t === 'object' ? `${t.key}:${t.value}` : t)
|
||||||
.join(' ');
|
.join(' ');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue