Something went wrong. Try again.
A free, open-source, self-hosted place to write a novel.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import { describe, expect, it } from 'vitest';import { sql } from 'drizzle-orm';import { db } from '#lib/server/db/index.ts';import { readDatabaseState, stampOpenedVersion } from '#lib/server/instance.ts';import { BUILD } from '#lib/server/version.ts';
/** * A rollback reads the instance row to name the build that wrote the shape it is * looking at, so every boot must write it and it must name this build. */describe('the database stamp', () => { it('names this build after it opens the database', () => { stampOpenedVersion();
const state = readDatabaseState();
expect(state.created).toBe(true); expect(state.version).toBe(BUILD.version); expect(state.openedAt).not.toBeNull(); });
it('is current with the migrations this build ships', () => { // The app migrates on import, so a failure here means a migration the // database never received, or a reader in the wrong folder. const state = readDatabaseState();
expect(state.newerThanBuild).toBe(false); expect(state.applied).toEqual(state.local); });});
/** * The switch is the admin's to open, because claiming the instance closes sign-up. * A settings row that names no value must therefore arrive closed. */describe('the sign-up default', () => { it('leaves sign-up closed for a row that names no value', () => { // Rolled back, because this row is shared with every other spec in the project. db.$client.exec('begin');
try { db.run(sql`delete from instance_setting`); db.run(sql`insert into instance_setting (id, created_at, updated_at) values (1, 0, 0)`);
const row = db.get<{ signup_open: number }>( sql`select signup_open from instance_setting where id = 1` );
expect(row?.signup_open).toBe(0); } finally { db.$client.exec('rollback'); } });});