mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Fix tests
This commit is contained in:
parent
3a82c98c21
commit
5e4a94457f
2 changed files with 8 additions and 7 deletions
|
|
@ -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);
|
||||||
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();
|
const customEventZaps = await kysely.selectFrom('event_zaps').selectAll().execute();
|
||||||
|
|
||||||
assertEquals(zapReceipts.length, 1); // basic check
|
assertEquals(zapReceipts.length, 1); // basic check
|
||||||
|
|
|
||||||
13
src/test.ts
13
src/test.ts
|
|
@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
import { Database as Sqlite } from '@db/sqlite';
|
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 { NostrEvent } from '@nostrify/nostrify';
|
||||||
import { DenoSqlite3Dialect } from '@soapbox/kysely-deno-sqlite';
|
import { DenoSqlite3Dialect } from '@soapbox/kysely-deno-sqlite';
|
||||||
import { finalizeEvent, generateSecretKey } from 'nostr-tools';
|
import { finalizeEvent, generateSecretKey } from 'nostr-tools';
|
||||||
|
|
@ -10,7 +10,7 @@ import { FileMigrationProvider, Kysely, Migrator } from 'kysely';
|
||||||
import { PostgresJSDialect, PostgresJSDialectConfig } from 'kysely-postgres-js';
|
import { PostgresJSDialect, PostgresJSDialectConfig } from 'kysely-postgres-js';
|
||||||
import postgres from 'postgres';
|
import postgres from 'postgres';
|
||||||
|
|
||||||
import { DittoDB } from '@/db/DittoDB.ts';
|
import { DittoDatabase, DittoDB } from '@/db/DittoDB.ts';
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
import { DittoTables } from '@/db/DittoTables.ts';
|
||||||
import { purifyEvent } from '@/storages/hydrate.ts';
|
import { purifyEvent } from '@/storages/hydrate.ts';
|
||||||
import { KyselyLogger } from '@/db/KyselyLogger.ts';
|
import { KyselyLogger } from '@/db/KyselyLogger.ts';
|
||||||
|
|
@ -99,7 +99,7 @@ export const createTestDB = async (databaseUrl?: string) => {
|
||||||
|
|
||||||
console.warn(`Using: ${dialect}`);
|
console.warn(`Using: ${dialect}`);
|
||||||
|
|
||||||
let kysely: Kysely<DittoTables>;
|
let kysely: DittoDatabase['kysely'];
|
||||||
|
|
||||||
if (dialect === 'sqlite') {
|
if (dialect === 'sqlite') {
|
||||||
// migration 021_pgfts_index.ts calls 'Conf.db.dialect',
|
// 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.
|
// The following line ensures to NOT use the DATABASE_URL that may exist in an .env file.
|
||||||
Deno.env.set('DATABASE_URL', 'sqlite://:memory:');
|
Deno.env.set('DATABASE_URL', 'sqlite://:memory:');
|
||||||
|
|
||||||
kysely = new Kysely<DittoTables>({
|
kysely = new Kysely({
|
||||||
dialect: new DenoSqlite3Dialect({
|
dialect: new DenoSqlite3Dialect({
|
||||||
database: new Sqlite(':memory:'),
|
database: new Sqlite(':memory:'),
|
||||||
}),
|
}),
|
||||||
});
|
}) as Kysely<DittoTables> & Kysely<NDatabaseSchema>;
|
||||||
} else {
|
} else {
|
||||||
kysely = new Kysely({
|
kysely = new Kysely({
|
||||||
// @ts-ignore Kysely version mismatch.
|
// @ts-ignore Kysely version mismatch.
|
||||||
|
|
@ -121,13 +121,14 @@ export const createTestDB = async (databaseUrl?: string) => {
|
||||||
}) as unknown as PostgresJSDialectConfig['postgres'],
|
}) as unknown as PostgresJSDialectConfig['postgres'],
|
||||||
}),
|
}),
|
||||||
log: KyselyLogger,
|
log: KyselyLogger,
|
||||||
});
|
}) as Kysely<DittoTables> & Kysely<NPostgresSchema>;
|
||||||
}
|
}
|
||||||
await DittoDB.migrate(kysely);
|
await DittoDB.migrate(kysely);
|
||||||
|
|
||||||
const store = new EventsDB(kysely);
|
const store = new EventsDB(kysely);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
dialect,
|
||||||
store,
|
store,
|
||||||
kysely,
|
kysely,
|
||||||
[Symbol.asyncDispose]: async () => {
|
[Symbol.asyncDispose]: async () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue