chore: prettier formatting

This commit is contained in:
Eyal Toledano
2025-04-09 18:20:47 -04:00
parent 12519946b4
commit 4f68bf3b47
7 changed files with 487 additions and 376 deletions

View File

@@ -3,7 +3,10 @@
*/
import { jest } from '@jest/globals';
import { sampleTasks, emptySampleTasks } from '../../tests/fixtures/sample-tasks.js';
import {
sampleTasks,
emptySampleTasks
} from '../../tests/fixtures/sample-tasks.js';
// Mock functions that need jest.fn methods
const mockParsePRD = jest.fn().mockResolvedValue(undefined);
@@ -655,34 +658,49 @@ describe('Commands Module', () => {
existsSync: jest.fn().mockReturnValue(true),
readFileSync: jest.fn().mockReturnValue(JSON.stringify(sampleTasks))
};
// Create a mock task manager with an addTask function that resolves to taskId 5
mockTaskManager = {
addTask: jest.fn().mockImplementation((file, prompt, dependencies, priority, session, research, generateFiles, manualTaskData) => {
// Return the next ID after the last one in sample tasks
const newId = sampleTasks.tasks.length + 1;
return Promise.resolve(newId.toString());
})
addTask: jest
.fn()
.mockImplementation(
(
file,
prompt,
dependencies,
priority,
session,
research,
generateFiles,
manualTaskData
) => {
// Return the next ID after the last one in sample tasks
const newId = sampleTasks.tasks.length + 1;
return Promise.resolve(newId.toString());
}
)
};
// Create a simplified version of the add-task action function for testing
addTaskAction = async (cmd, options) => {
options = options || {}; // Ensure options is not undefined
const isManualCreation = options.title && options.description;
// Get prompt directly or from p shorthand
const prompt = options.prompt || options.p;
// Validate that either prompt or title+description are provided
if (!prompt && !isManualCreation) {
throw new Error('Either --prompt or both --title and --description must be provided');
throw new Error(
'Either --prompt or both --title and --description must be provided'
);
}
// Prepare dependencies if provided
let dependencies = [];
if (options.dependencies) {
dependencies = options.dependencies.split(',').map(id => id.trim());
dependencies = options.dependencies.split(',').map((id) => id.trim());
}
// Create manual task data if title and description are provided
@@ -695,13 +713,13 @@ describe('Commands Module', () => {
testStrategy: options.testStrategy || ''
};
}
// Call addTask with the right parameters
return await mockTaskManager.addTask(
options.file || 'tasks/tasks.json',
prompt,
dependencies,
options.priority || 'medium',
options.priority || 'medium',
{ session: process.env },
options.research || options.r || false,
null,
@@ -713,19 +731,21 @@ describe('Commands Module', () => {
test('should throw error if no prompt or manual task data provided', async () => {
// Call without required params
const options = { file: 'tasks/tasks.json' };
await expect(async () => {
await addTaskAction(undefined, options);
}).rejects.toThrow('Either --prompt or both --title and --description must be provided');
}).rejects.toThrow(
'Either --prompt or both --title and --description must be provided'
);
});
test('should handle short-hand flag -p for prompt', async () => {
// Use -p as prompt short-hand
const options = {
const options = {
p: 'Create a login component',
file: 'tasks/tasks.json'
};
await addTaskAction(undefined, options);
// Check that task manager was called with correct arguments
@@ -737,17 +757,17 @@ describe('Commands Module', () => {
{ session: process.env },
false, // Research flag
null, // Generate files parameter
null // Manual task data
null // Manual task data
);
});
test('should handle short-hand flag -r for research', async () => {
const options = {
const options = {
prompt: 'Create authentication system',
r: true,
file: 'tasks/tasks.json'
};
await addTaskAction(undefined, options);
// Check that task manager was called with correct research flag
@@ -759,18 +779,18 @@ describe('Commands Module', () => {
{ session: process.env },
true, // Research flag should be true
null, // Generate files parameter
null // Manual task data
null // Manual task data
);
});
test('should handle manual task creation with title and description', async () => {
const options = {
const options = {
title: 'Login Component',
description: 'Create a reusable login form',
details: 'Implementation details here',
file: 'tasks/tasks.json'
};
await addTaskAction(undefined, options);
// Check that task manager was called with correct manual task data
@@ -782,7 +802,8 @@ describe('Commands Module', () => {
{ session: process.env },
false,
null, // Generate files parameter
{ // Manual task data
{
// Manual task data
title: 'Login Component',
description: 'Create a reusable login form',
details: 'Implementation details here',
@@ -792,12 +813,12 @@ describe('Commands Module', () => {
});
test('should handle dependencies parameter', async () => {
const options = {
const options = {
prompt: 'Create user settings page',
dependencies: '1, 3, 5', // Dependencies with spaces
file: 'tasks/tasks.json'
};
await addTaskAction(undefined, options);
// Check that dependencies are parsed correctly
@@ -809,17 +830,17 @@ describe('Commands Module', () => {
{ session: process.env },
false,
null, // Generate files parameter
null // Manual task data
null // Manual task data
);
});
test('should handle priority parameter', async () => {
const options = {
const options = {
prompt: 'Create navigation menu',
priority: 'high',
file: 'tasks/tasks.json'
};
await addTaskAction(undefined, options);
// Check that priority is passed correctly
@@ -831,16 +852,16 @@ describe('Commands Module', () => {
{ session: process.env },
false,
null, // Generate files parameter
null // Manual task data
null // Manual task data
);
});
test('should use default values for optional parameters', async () => {
const options = {
const options = {
prompt: 'Basic task',
file: 'tasks/tasks.json'
};
await addTaskAction(undefined, options);
// Check that default values are used
@@ -852,7 +873,7 @@ describe('Commands Module', () => {
{ session: process.env },
false, // Research is false by default
null, // Generate files parameter
null // Manual task data
null // Manual task data
);
});
});