Add events test

This commit is contained in:
Alex Gleason 2023-08-10 14:56:27 -05:00
parent 63772022cf
commit 48343c8035
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
4 changed files with 38 additions and 2 deletions

View File

@ -9,7 +9,8 @@
"check": "deno check --unstable src/server.ts"
},
"imports": {
"@/": "./src/"
"@/": "./src/",
"~/": "./"
},
"lint": {
"include": ["src/"],

View File

@ -0,0 +1,15 @@
{
"kind": 1,
"content": "I'm vegan btw",
"tags": [
[
"proxy",
"https://gleasonator.com/objects/8f6fac53-4f66-4c6e-ac7d-92e5e78c3e79",
"activitypub"
]
],
"pubkey": "79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6",
"created_at": 1691091365,
"id": "55920b758b9c7b17854b6e3d44e6a02a83d1cb49e1227e75a30426dea94d4cb2",
"sig": "a72f12c08f18e85d98fb92ae89e2fe63e48b8864c5e10fbdd5335f3c9f936397a6b0a7350efe251f8168b1601d7012d4a6d0ee6eec958067cf22a14f5a5ea579"
}

17
src/db/events.test.ts Normal file
View File

@ -0,0 +1,17 @@
import event55920b75 from '~/fixtures/events/55920b75.json' assert { type: 'json' };
import { assertEquals } from '@/deps-test.ts';
import { getFilter, insertEvent } from './events.ts';
Deno.test('insert and filter events', async () => {
await insertEvent(event55920b75);
assertEquals(await getFilter({ kinds: [1] }), [event55920b75]);
assertEquals(await getFilter({ kinds: [3] }), []);
assertEquals(await getFilter({ since: 1691091000 }), [event55920b75]);
assertEquals(await getFilter({ until: 1691091000 }), []);
assertEquals(
await getFilter({ '#proxy': ['https://gleasonator.com/objects/8f6fac53-4f66-4c6e-ac7d-92e5e78c3e79'] }),
[event55920b75],
);
});

View File

@ -50,7 +50,10 @@ function insertEvent(event: SignedEvent): Promise<void> {
}
function getFilterQuery(filter: Filter) {
let query = db.selectFrom('events').selectAll().orderBy('created_at', 'desc');
let query = db
.selectFrom('events')
.select(['id', 'kind', 'pubkey', 'content', 'tags', 'created_at', 'sig'])
.orderBy('created_at', 'desc');
for (const key of Object.keys(filter)) {
switch (key as keyof Filter) {