37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
import { describe, it, expect, beforeAll } from 'vitest';
|
|
import { resetDb, withClient } from '../helpers/db.js';
|
|
import { migrateUp } from '../../lib/db/migrate.js';
|
|
|
|
describe('migration 001 — core', () => {
|
|
beforeAll(async () => { await resetDb(); await migrateUp(); });
|
|
|
|
it('creates spaces, projects, tasks tables', async () => {
|
|
await withClient(async (c) => {
|
|
for (const t of ['spaces', 'projects', 'tasks']) {
|
|
const { rows } = await c.query(
|
|
`SELECT to_regclass('public.' || $1) AS t;`, [t]
|
|
);
|
|
expect(rows[0].t).toBe(t);
|
|
}
|
|
});
|
|
});
|
|
|
|
it('enforces UNIQUE(space_id, slug) on projects', async () => {
|
|
await withClient(async (c) => {
|
|
const { rows: [s] } = await c.query(
|
|
`INSERT INTO spaces(slug, name) VALUES('test', 'Test') RETURNING id;`
|
|
);
|
|
await c.query(
|
|
`INSERT INTO projects(space_id, slug, name) VALUES($1, 'a', 'A');`,
|
|
[s.id]
|
|
);
|
|
await expect(
|
|
c.query(
|
|
`INSERT INTO projects(space_id, slug, name) VALUES($1, 'a', 'B');`,
|
|
[s.id]
|
|
)
|
|
).rejects.toThrow(/duplicate key/i);
|
|
});
|
|
});
|
|
});
|