30 lines
1.4 KiB
JavaScript
30 lines
1.4 KiB
JavaScript
import { describe, it, expect, beforeAll } from 'vitest';
|
|
import { fileURLToPath } from 'url';
|
|
import { pool } from '../../lib/db/pool.js';
|
|
import { resetDb } from '../helpers/db.js';
|
|
import { migrateUp } from '../../lib/db/migrate.js';
|
|
import { ensureSpace } from '../../migrate/spaces.js';
|
|
import { importPlans } from '../../migrate/sources/plans.js';
|
|
|
|
const DIR = fileURLToPath(new URL('../fixtures/plans', import.meta.url));
|
|
let spaceId;
|
|
beforeAll(async () => { await resetDb(); await migrateUp(); spaceId = await ensureSpace('plans', 'Plans'); });
|
|
|
|
describe('plans importer', () => {
|
|
it('imports each .md as a page, idempotently', async () => {
|
|
const r1 = await importPlans({ dir: DIR, spaceId });
|
|
expect(r1.created).toBe(2);
|
|
const { rows } = await pool.query(`SELECT title FROM pages WHERE space_id=$1 ORDER BY title`, [spaceId]);
|
|
expect(rows.map(r => r.title)).toEqual(['Alpha Plan', 'Beta']);
|
|
const r2 = await importPlans({ dir: DIR, spaceId }); // re-run
|
|
expect(r2.created).toBe(0);
|
|
});
|
|
it('dry-run writes nothing', async () => {
|
|
await resetDb(); await migrateUp(); const s = await ensureSpace('plans', 'Plans');
|
|
const r = await importPlans({ dir: DIR, spaceId: s, dryRun: true });
|
|
expect(r.created).toBe(2);
|
|
const { rows } = await pool.query(`SELECT count(*)::int n FROM pages WHERE space_id=$1`, [s]);
|
|
expect(rows[0].n).toBe(0);
|
|
});
|
|
});
|