From 48343c80358999e8b8f274aab184fb37df3bba00 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 10 Aug 2023 14:56:27 -0500 Subject: [PATCH] Add events test --- deno.json | 3 ++- fixtures/events/55920b75.json | 15 +++++++++++++++ src/db/events.test.ts | 17 +++++++++++++++++ src/db/events.ts | 5 ++++- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 fixtures/events/55920b75.json create mode 100644 src/db/events.test.ts diff --git a/deno.json b/deno.json index f57d2de..5233fa9 100644 --- a/deno.json +++ b/deno.json @@ -9,7 +9,8 @@ "check": "deno check --unstable src/server.ts" }, "imports": { - "@/": "./src/" + "@/": "./src/", + "~/": "./" }, "lint": { "include": ["src/"], diff --git a/fixtures/events/55920b75.json b/fixtures/events/55920b75.json new file mode 100644 index 0000000..f902786 --- /dev/null +++ b/fixtures/events/55920b75.json @@ -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" +} \ No newline at end of file diff --git a/src/db/events.test.ts b/src/db/events.test.ts new file mode 100644 index 0000000..26fe7bf --- /dev/null +++ b/src/db/events.test.ts @@ -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], + ); +}); diff --git a/src/db/events.ts b/src/db/events.ts index 956517a..473f30a 100644 --- a/src/db/events.ts +++ b/src/db/events.ts @@ -50,7 +50,10 @@ function insertEvent(event: SignedEvent): Promise { } 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) {