Add events test
This commit is contained in:
parent
63772022cf
commit
48343c8035
|
@ -9,7 +9,8 @@
|
|||
"check": "deno check --unstable src/server.ts"
|
||||
},
|
||||
"imports": {
|
||||
"@/": "./src/"
|
||||
"@/": "./src/",
|
||||
"~/": "./"
|
||||
},
|
||||
"lint": {
|
||||
"include": ["src/"],
|
||||
|
|
|
@ -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"
|
||||
}
|
|
@ -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],
|
||||
);
|
||||
});
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue