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:56:38 +00:00
commit fdc8fe9abe
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 { eventFixture } from '@/test.ts';
import { Conf } from '@/config.ts';
import { DittoPgStore } from '@/storages/DittoPgStore.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 () => {
await using db = await createTestDB({ pure: true });
const { store } = db;
const { conf, store } = db;
const sk = generateSecretKey();
@ -168,7 +167,7 @@ Deno.test('admin can delete any event', async () => {
assertEquals(await store.query([{ kinds: [1] }]), [two, one]);
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]);
@ -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 () => {
await using db = await createTestDB({ pure: true });
const { store } = db;
const { conf, store } = db;
const event = genEvent();
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 assertRejects(

View file

@ -1,7 +1,7 @@
import { DittoConf } from '@ditto/conf';
import { DittoPolyPg } from '@ditto/db';
import { NostrEvent } from '@nostrify/nostrify';
import { Conf } from '@/config.ts';
import { DittoPgStore } from '@/storages/DittoPgStore.ts';
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. */
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();
const store = new DittoPgStore({
db,
timeout: Conf.db.timeouts.default,
pubkey: await Conf.signer.getPublicKey(),
timeout: conf.db.timeouts.default,
pubkey: await conf.signer.getPublicKey(),
pure: opts?.pure ?? false,
notify: true,
});
@ -28,6 +29,7 @@ export async function createTestDB(opts?: { pure?: boolean }) {
db,
...db,
store,
conf,
kysely: db.kysely,
[Symbol.asyncDispose]: async () => {
const { rows } = await sql<