30 lines
972 B
JavaScript
30 lines
972 B
JavaScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { resetDb, withClient } from '../helpers/db.js';
|
|
import { migrateUp } from '../../lib/db/migrate.js';
|
|
|
|
describe('migration 002 — knowledge', () => {
|
|
beforeEach(async () => { await resetDb(); await migrateUp(); });
|
|
|
|
it('creates pages, page_revisions, refs', async () => {
|
|
await withClient(async (c) => {
|
|
for (const t of ['pages','page_revisions','refs']) {
|
|
const { rows } = await c.query(
|
|
`SELECT to_regclass('public.' || $1) AS t;`, [t]
|
|
);
|
|
expect(rows[0].t).toBe(t);
|
|
}
|
|
});
|
|
});
|
|
|
|
it('refs.kind check enforces enum', async () => {
|
|
await withClient(async (c) => {
|
|
const { rows: [s] } = await c.query(
|
|
`INSERT INTO spaces(slug,name) VALUES('h','H') RETURNING id;`
|
|
);
|
|
await expect(c.query(
|
|
`INSERT INTO refs(space_id, kind) VALUES($1, 'invalid');`, [s.id]
|
|
)).rejects.toThrow(/check/i);
|
|
});
|
|
});
|
|
});
|