feat(repos): spaces, projects, tasks with audit stub

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-05-31 02:11:31 +10:00
parent 05ee9b3f41
commit 951016385a
8 changed files with 283 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
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';
const owner = { kind: 'user', id: null };
beforeEach(async () => { await resetDb(); await migrateUp(); });
describe('spaces repo', () => {
it('creates and returns a space', async () => {
const s = await spaces.create({ slug: 'homelab', name: 'Homelab' }, owner);
expect(s.id).toBeDefined();
expect(s.slug).toBe('homelab');
});
it('getBySlug returns the row', async () => {
await spaces.create({ slug: 'a', name: 'A' }, owner);
const got = await spaces.getBySlug('a');
expect(got.name).toBe('A');
});
it('list returns all', async () => {
await spaces.create({ slug: 'a', name: 'A' }, owner);
await spaces.create({ slug: 'b', name: 'B' }, owner);
const all = await spaces.list();
expect(all).toHaveLength(2);
});
it('update changes fields and bumps updated_at', async () => {
const s = await spaces.create({ slug: 'a', name: 'A' }, owner);
const u = await spaces.update(s.id, { name: 'Renamed' }, owner);
expect(u.name).toBe('Renamed');
expect(new Date(u.updated_at).getTime())
.toBeGreaterThanOrEqual(new Date(s.updated_at).getTime());
});
it('del removes the row', async () => {
const s = await spaces.create({ slug: 'a', name: 'A' }, owner);
await spaces.del(s.id, owner);
expect(await spaces.getBySlug('a')).toBeUndefined();
});
});