import { describe, it, expect, beforeEach } from 'vitest'; import { resetDb } from '../helpers/db.js'; import { migrateUp } from '../../lib/db/migrate.js'; import { create, listBySpace, update } from '../../lib/db/repos/pages.js'; import { create as createSpace } from '../../lib/db/repos/spaces.js'; const actor = { kind: 'user', id: null }; beforeEach(async () => { await resetDb(); await migrateUp(); }); describe('page ordering', () => { it('orders by position then title', async () => { const space = await createSpace({ slug: 'ord-test', name: 'Ord' }, actor); const sid = space.id; const a = await create({ space_id: sid, slug: 'a', title: 'Zzz', body_md: '' }, actor); const b = await create({ space_id: sid, slug: 'b', title: 'Aaa', body_md: '' }, actor); await update(a.id, { position: 1 }, actor); await update(b.id, { position: 9 }, actor); const list = await listBySpace(sid); expect(list.map(p => p.title)).toEqual(['Zzz', 'Aaa']); }); });