From 5e4a94457fb7527240647428a66a4dc5266d48e8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 12 Aug 2024 14:57:17 -0500 Subject: [PATCH] Fix tests --- src/pipeline.test.ts | 2 +- src/test.ts | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pipeline.test.ts b/src/pipeline.test.ts index 3a196c16..2af2b8c3 100644 --- a/src/pipeline.test.ts +++ b/src/pipeline.test.ts @@ -37,7 +37,7 @@ Deno.test('store one zap receipt in nostr_events; convert it into event_zaps tab await handleZaps(kysely, event); await handleZaps(kysely, event); - const zapReceipts = await kysely.selectFrom('nostr_events').selectAll().execute(); + const zapReceipts = await db.store.query([{}]); const customEventZaps = await kysely.selectFrom('event_zaps').selectAll().execute(); assertEquals(zapReceipts.length, 1); // basic check diff --git a/src/test.ts b/src/test.ts index c3c0db7b..4d683d8b 100644 --- a/src/test.ts +++ b/src/test.ts @@ -2,7 +2,7 @@ import fs from 'node:fs/promises'; import path from 'node:path'; import { Database as Sqlite } from '@db/sqlite'; -import { NDatabase } from '@nostrify/db'; +import { NDatabase, NDatabaseSchema, NPostgresSchema } from '@nostrify/db'; import { NostrEvent } from '@nostrify/nostrify'; import { DenoSqlite3Dialect } from '@soapbox/kysely-deno-sqlite'; import { finalizeEvent, generateSecretKey } from 'nostr-tools'; @@ -10,7 +10,7 @@ import { FileMigrationProvider, Kysely, Migrator } from 'kysely'; import { PostgresJSDialect, PostgresJSDialectConfig } from 'kysely-postgres-js'; import postgres from 'postgres'; -import { DittoDB } from '@/db/DittoDB.ts'; +import { DittoDatabase, DittoDB } from '@/db/DittoDB.ts'; import { DittoTables } from '@/db/DittoTables.ts'; import { purifyEvent } from '@/storages/hydrate.ts'; import { KyselyLogger } from '@/db/KyselyLogger.ts'; @@ -99,7 +99,7 @@ export const createTestDB = async (databaseUrl?: string) => { console.warn(`Using: ${dialect}`); - let kysely: Kysely; + let kysely: DittoDatabase['kysely']; if (dialect === 'sqlite') { // migration 021_pgfts_index.ts calls 'Conf.db.dialect', @@ -107,11 +107,11 @@ export const createTestDB = async (databaseUrl?: string) => { // The following line ensures to NOT use the DATABASE_URL that may exist in an .env file. Deno.env.set('DATABASE_URL', 'sqlite://:memory:'); - kysely = new Kysely({ + kysely = new Kysely({ dialect: new DenoSqlite3Dialect({ database: new Sqlite(':memory:'), }), - }); + }) as Kysely & Kysely; } else { kysely = new Kysely({ // @ts-ignore Kysely version mismatch. @@ -121,13 +121,14 @@ export const createTestDB = async (databaseUrl?: string) => { }) as unknown as PostgresJSDialectConfig['postgres'], }), log: KyselyLogger, - }); + }) as Kysely & Kysely; } await DittoDB.migrate(kysely); const store = new EventsDB(kysely); return { + dialect, store, kysely, [Symbol.asyncDispose]: async () => {