feat(repos): pages with auto-revisions, refs with upsertByExternal
This commit is contained in:
33
tests/repos/pages.test.js
Normal file
33
tests/repos/pages.test.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { resetDb } from '../helpers/db.js';
|
||||
import { migrateUp } from '../../lib/db/migrate.js';
|
||||
import * as spaces from '../../lib/db/repos/spaces.js';
|
||||
import * as pages from '../../lib/db/repos/pages.js';
|
||||
|
||||
const owner = { kind: 'user', id: null };
|
||||
|
||||
beforeEach(async () => { await resetDb(); await migrateUp(); });
|
||||
|
||||
describe('pages repo', () => {
|
||||
it('creates a page and auto-snapshots a revision', async () => {
|
||||
const s = await spaces.create({ slug: 'h', name: 'H' }, owner);
|
||||
const p = await pages.create(
|
||||
{ space_id: s.id, slug: 'a', title: 'A', body_md: 'hello' }, owner
|
||||
);
|
||||
expect(p.body_md).toBe('hello');
|
||||
const revs = await pages.listRevisions(p.id);
|
||||
expect(revs).toHaveLength(1);
|
||||
expect(revs[0].body_md).toBe('hello');
|
||||
});
|
||||
|
||||
it('updating body adds a revision', async () => {
|
||||
const s = await spaces.create({ slug: 'h', name: 'H' }, owner);
|
||||
const p = await pages.create(
|
||||
{ space_id: s.id, slug: 'a', title: 'A', body_md: 'v1' }, owner
|
||||
);
|
||||
await pages.update(p.id, { body_md: 'v2' }, owner);
|
||||
const revs = await pages.listRevisions(p.id);
|
||||
expect(revs).toHaveLength(2);
|
||||
expect(revs[0].body_md).toBe('v2'); // newest first
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user