Merge branch 'conf-tests' into 'main'

Remove `@/config.ts` imports from tests

See merge request soapbox-pub/ditto!696
This commit is contained in:
Alex Gleason 2025-02-27 19:57:48 +00:00
commit 549f3ebc5d
2 changed files with 10 additions and 9 deletions

View file

@ -5,7 +5,6 @@ import { generateSecretKey } from 'nostr-tools';
import { RelayError } from '@/RelayError.ts'; import { RelayError } from '@/RelayError.ts';
import { eventFixture } from '@/test.ts'; import { eventFixture } from '@/test.ts';
import { Conf } from '@/config.ts';
import { DittoPgStore } from '@/storages/DittoPgStore.ts'; import { DittoPgStore } from '@/storages/DittoPgStore.ts';
import { createTestDB } from '@/test.ts'; import { createTestDB } from '@/test.ts';
@ -152,7 +151,7 @@ Deno.test("user cannot delete another user's event", async () => {
Deno.test('admin can delete any event', async () => { Deno.test('admin can delete any event', async () => {
await using db = await createTestDB({ pure: true }); await using db = await createTestDB({ pure: true });
const { store } = db; const { conf, store } = db;
const sk = generateSecretKey(); const sk = generateSecretKey();
@ -168,7 +167,7 @@ Deno.test('admin can delete any event', async () => {
assertEquals(await store.query([{ kinds: [1] }]), [two, one]); assertEquals(await store.query([{ kinds: [1] }]), [two, one]);
await store.event( await store.event(
genEvent({ kind: 5, tags: [['e', one.id]] }, Conf.seckey), // admin sk genEvent({ kind: 5, tags: [['e', one.id]] }, conf.seckey), // admin sk
); );
assertEquals(await store.query([{ kinds: [1] }]), [two]); assertEquals(await store.query([{ kinds: [1] }]), [two]);
@ -176,12 +175,12 @@ Deno.test('admin can delete any event', async () => {
Deno.test('throws a RelayError when inserting an event deleted by the admin', async () => { Deno.test('throws a RelayError when inserting an event deleted by the admin', async () => {
await using db = await createTestDB({ pure: true }); await using db = await createTestDB({ pure: true });
const { store } = db; const { conf, store } = db;
const event = genEvent(); const event = genEvent();
await store.event(event); await store.event(event);
const deletion = genEvent({ kind: 5, tags: [['e', event.id]] }, Conf.seckey); const deletion = genEvent({ kind: 5, tags: [['e', event.id]] }, conf.seckey);
await store.event(deletion); await store.event(deletion);
await assertRejects( await assertRejects(

View file

@ -1,7 +1,7 @@
import { DittoConf } from '@ditto/conf';
import { DittoPolyPg } from '@ditto/db'; import { DittoPolyPg } from '@ditto/db';
import { NostrEvent } from '@nostrify/nostrify'; import { NostrEvent } from '@nostrify/nostrify';
import { Conf } from '@/config.ts';
import { DittoPgStore } from '@/storages/DittoPgStore.ts'; import { DittoPgStore } from '@/storages/DittoPgStore.ts';
import { sql } from 'kysely'; import { sql } from 'kysely';
@ -13,13 +13,14 @@ export async function eventFixture(name: string): Promise<NostrEvent> {
/** Create a database for testing. It uses `DATABASE_URL`, or creates an in-memory database by default. */ /** Create a database for testing. It uses `DATABASE_URL`, or creates an in-memory database by default. */
export async function createTestDB(opts?: { pure?: boolean }) { export async function createTestDB(opts?: { pure?: boolean }) {
const db = new DittoPolyPg(Conf.databaseUrl, { poolSize: 1 }); const conf = new DittoConf(Deno.env);
const db = new DittoPolyPg(conf.databaseUrl, { poolSize: 1 });
await db.migrate(); await db.migrate();
const store = new DittoPgStore({ const store = new DittoPgStore({
db, db,
timeout: Conf.db.timeouts.default, timeout: conf.db.timeouts.default,
pubkey: await Conf.signer.getPublicKey(), pubkey: await conf.signer.getPublicKey(),
pure: opts?.pure ?? false, pure: opts?.pure ?? false,
notify: true, notify: true,
}); });
@ -28,6 +29,7 @@ export async function createTestDB(opts?: { pure?: boolean }) {
db, db,
...db, ...db,
store, store,
conf,
kysely: db.kysely, kysely: db.kysely,
[Symbol.asyncDispose]: async () => { [Symbol.asyncDispose]: async () => {
const { rows } = await sql< const { rows } = await sql<