37 lines
1.5 KiB
JavaScript
37 lines
1.5 KiB
JavaScript
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 projects from '../../lib/db/repos/projects.js';
|
|
import * as tasks from '../../lib/db/repos/tasks.js';
|
|
|
|
const owner = { kind: 'user', id: null };
|
|
|
|
beforeEach(async () => { await resetDb(); await migrateUp(); });
|
|
|
|
describe('tasks repo', () => {
|
|
it('creates a task with optional project', async () => {
|
|
const s = await spaces.create({ slug: 'h', name: 'H' }, owner);
|
|
const t = await tasks.create({ space_id: s.id, title: 'do it' }, owner);
|
|
expect(t.status).toBe('todo');
|
|
expect(t.project_id).toBeNull();
|
|
});
|
|
|
|
it('marking done sets completed_at', async () => {
|
|
const s = await spaces.create({ slug: 'h', name: 'H' }, owner);
|
|
const t = await tasks.create({ space_id: s.id, title: 'x' }, owner);
|
|
const u = await tasks.update(t.id, { status: 'done' }, owner);
|
|
expect(u.status).toBe('done');
|
|
expect(u.completed_at).not.toBeNull();
|
|
});
|
|
|
|
it('listByProject returns project tasks only', async () => {
|
|
const s = await spaces.create({ slug: 'h', name: 'H' }, owner);
|
|
const p = await projects.create({ space_id: s.id, slug: 'p', name: 'P' }, owner);
|
|
await tasks.create({ space_id: s.id, project_id: p.id, title: 'a' }, owner);
|
|
await tasks.create({ space_id: s.id, title: 'orphan' }, owner);
|
|
const list = await tasks.listByProject(p.id);
|
|
expect(list).toHaveLength(1);
|
|
});
|
|
});
|