veritas-kanban/cli/src/__tests__/task-execution-policy.test.ts
Brad Groux b704ab92d0
Some checks failed
CI / Lint & Type Check (push) Has been cancelled
CI / Workspace Unit Tests (push) Has been cancelled
CI / Build (push) Has been cancelled
CI / Security Audit (push) Has been cancelled
feat: add provider-neutral task envelope contracts (#891) (#894)
Co-authored-by: bradgroux <brad@digitalmeld.io>
2026-07-16 12:48:48 -05:00

65 lines
1.9 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest';
import { Command } from 'commander';
const { mockApi, mockFindTask } = vi.hoisted(() => ({
mockApi: vi.fn(),
mockFindTask: vi.fn(),
}));
vi.mock('../utils/api.js', () => ({ api: mockApi }));
vi.mock('../utils/find.js', () => ({ findTask: mockFindTask }));
import { registerTaskCommands } from '../commands/tasks.js';
describe('vk task execution policy', () => {
beforeEach(() => {
vi.clearAllMocks();
mockApi.mockResolvedValue({
id: 'task_1',
title: 'Policy task',
type: 'code',
status: 'todo',
priority: 'medium',
created: '2026-07-16T00:00:00.000Z',
updated: '2026-07-16T00:00:00.000Z',
});
mockFindTask.mockResolvedValue({ id: 'task_1' });
vi.spyOn(console, 'log').mockImplementation(() => undefined);
});
it('forwards a task commit policy on create', async () => {
const program = new Command();
program.exitOverride();
registerTaskCommands(program);
await program.parseAsync(['create', 'Policy task', '--commit-policy', 'forbidden', '--json'], {
from: 'user',
});
expect(mockApi).toHaveBeenCalledWith('/api/tasks', {
method: 'POST',
body: JSON.stringify({
title: 'Policy task',
type: 'code',
description: '',
priority: 'medium',
executionPolicy: { commitPolicy: 'forbidden' },
}),
});
});
it('forwards a task commit policy on update', async () => {
const program = new Command();
program.exitOverride();
registerTaskCommands(program);
await program.parseAsync(['update', 'task_1', '--commit-policy', 'required', '--json'], {
from: 'user',
});
expect(mockApi).toHaveBeenCalledWith('/api/tasks/task_1', {
method: 'PATCH',
body: JSON.stringify({ executionPolicy: { commitPolicy: 'required' } }),
});
});
});