11import { describe , it , expect , beforeEach } from '@jest/globals' ;
2- import { setupTestContext , teardownTestContext , TestContext , createTestProject } from '../test-helpers.js' ;
2+ import { setupTestContext , teardownTestContext , TestContext , createTestProject , verifyCallToolResult , verifyTaskInFile , verifyToolExecutionError , verifyProtocolError } from '../test-helpers.js' ;
3+ import { CallToolResult } from '@modelcontextprotocol/sdk/types.js' ;
34
45describe ( 'add_tasks_to_project Tool' , ( ) => {
56 let context : TestContext ;
7+ let projectId : string ;
68
79 beforeEach ( async ( ) => {
810 context = await setupTestContext ( ) ;
11+ // Create a test project for each test case
12+ projectId = await createTestProject ( context . client ) ;
913 } ) ;
1014
1115 afterEach ( async ( ) => {
1216 await teardownTestContext ( context ) ;
1317 } ) ;
1418
1519 describe ( 'Success Cases' , ( ) => {
16- // TODO: Add success test cases
20+ it ( 'should add a single task to project' , async ( ) => {
21+ const result = await context . client . callTool ( {
22+ name : "add_tasks_to_project" ,
23+ arguments : {
24+ projectId,
25+ tasks : [
26+ { title : "New Task" , description : "A task to add" }
27+ ]
28+ }
29+ } ) as CallToolResult ;
30+
31+ verifyCallToolResult ( result ) ;
32+ expect ( result . isError ) . toBeFalsy ( ) ;
33+
34+ // Parse and verify response
35+ const responseData = JSON . parse ( ( result . content [ 0 ] as { text : string } ) . text ) ;
36+ expect ( responseData ) . toHaveProperty ( 'message' ) ;
37+ expect ( responseData ) . toHaveProperty ( 'newTasks' ) ;
38+ expect ( responseData . newTasks ) . toHaveLength ( 1 ) ;
39+ const newTask = responseData . newTasks [ 0 ] ;
40+
41+ // Verify task was added to file
42+ await verifyTaskInFile ( context . testFilePath , projectId , newTask . id , {
43+ title : "New Task" ,
44+ description : "A task to add" ,
45+ status : "not started" ,
46+ approved : false
47+ } ) ;
48+ } ) ;
49+
50+ it ( 'should add multiple tasks to project' , async ( ) => {
51+ const tasks = [
52+ { title : "Task 1" , description : "First task to add" } ,
53+ { title : "Task 2" , description : "Second task to add" } ,
54+ { title : "Task 3" , description : "Third task to add" }
55+ ] ;
56+
57+ const result = await context . client . callTool ( {
58+ name : "add_tasks_to_project" ,
59+ arguments : {
60+ projectId,
61+ tasks
62+ }
63+ } ) as CallToolResult ;
64+
65+ verifyCallToolResult ( result ) ;
66+ const responseData = JSON . parse ( ( result . content [ 0 ] as { text : string } ) . text ) ;
67+ expect ( responseData . newTasks ) . toHaveLength ( 3 ) ;
68+
69+ // Verify all tasks were added
70+ for ( let i = 0 ; i < tasks . length ; i ++ ) {
71+ await verifyTaskInFile ( context . testFilePath , projectId , responseData . newTasks [ i ] . id , {
72+ title : tasks [ i ] . title ,
73+ description : tasks [ i ] . description ,
74+ status : "not started"
75+ } ) ;
76+ }
77+ } ) ;
78+
79+ it ( 'should add tasks with tool and rule recommendations' , async ( ) => {
80+ const result = await context . client . callTool ( {
81+ name : "add_tasks_to_project" ,
82+ arguments : {
83+ projectId,
84+ tasks : [ {
85+ title : "Task with Recommendations" ,
86+ description : "Task with specific recommendations" ,
87+ toolRecommendations : "Use tool A and B" ,
88+ ruleRecommendations : "Follow rules X and Y"
89+ } ]
90+ }
91+ } ) as CallToolResult ;
92+
93+ verifyCallToolResult ( result ) ;
94+ const responseData = JSON . parse ( ( result . content [ 0 ] as { text : string } ) . text ) ;
95+ const newTask = responseData . newTasks [ 0 ] ;
96+
97+ await verifyTaskInFile ( context . testFilePath , projectId , newTask . id , {
98+ title : "Task with Recommendations" ,
99+ description : "Task with specific recommendations" ,
100+ toolRecommendations : "Use tool A and B" ,
101+ ruleRecommendations : "Follow rules X and Y"
102+ } ) ;
103+ } ) ;
104+
105+ it ( 'should handle empty tasks array' , async ( ) => {
106+ const result = await context . client . callTool ( {
107+ name : "add_tasks_to_project" ,
108+ arguments : {
109+ projectId,
110+ tasks : [ ]
111+ }
112+ } ) as CallToolResult ;
113+
114+ verifyCallToolResult ( result ) ;
115+ expect ( result . isError ) . toBeFalsy ( ) ;
116+ const responseData = JSON . parse ( ( result . content [ 0 ] as { text : string } ) . text ) ;
117+ expect ( responseData . newTasks ) . toHaveLength ( 0 ) ;
118+ } ) ;
17119 } ) ;
18120
19121 describe ( 'Error Cases' , ( ) => {
20- // TODO: Add error test cases
122+ it ( 'should return error for missing required parameters' , async ( ) => {
123+ try {
124+ await context . client . callTool ( {
125+ name : "add_tasks_to_project" ,
126+ arguments : {
127+ projectId
128+ // Missing tasks array
129+ }
130+ } ) ;
131+ expect ( true ) . toBe ( false ) ; // This line should never be reached
132+ } catch ( error ) {
133+ verifyProtocolError ( error , - 32602 , 'Invalid or missing required parameter' ) ;
134+ }
135+ } ) ;
136+
137+ it ( 'should return error for invalid project ID' , async ( ) => {
138+ const result = await context . client . callTool ( {
139+ name : "add_tasks_to_project" ,
140+ arguments : {
141+ projectId : "non-existent-project" ,
142+ tasks : [ { title : "Test Task" , description : "Test Description" } ]
143+ }
144+ } ) as CallToolResult ;
145+
146+ verifyToolExecutionError ( result , / P r o j e c t n o n - e x i s t e n t - p r o j e c t n o t f o u n d / ) ;
147+ } ) ;
148+
149+ it ( 'should return error for task with empty title' , async ( ) => {
150+ try {
151+ await context . client . callTool ( {
152+ name : "add_tasks_to_project" ,
153+ arguments : {
154+ projectId,
155+ tasks : [ { title : "" , description : "Test Description" } ]
156+ }
157+ } ) ;
158+ expect ( true ) . toBe ( false ) ; // This line should never be reached
159+ } catch ( error ) {
160+ verifyProtocolError ( error , - 32602 , 'Invalid or missing required parameter: title' ) ;
161+ }
162+ } ) ;
163+
164+ it ( 'should return error for task with empty description' , async ( ) => {
165+ try {
166+ await context . client . callTool ( {
167+ name : "add_tasks_to_project" ,
168+ arguments : {
169+ projectId,
170+ tasks : [ { title : "Test Task" , description : "" } ]
171+ }
172+ } ) ;
173+ expect ( true ) . toBe ( false ) ; // This line should never be reached
174+ } catch ( error ) {
175+ verifyProtocolError ( error , - 32602 , 'Invalid or missing required parameter: description' ) ;
176+ }
177+ } ) ;
21178 } ) ;
22179} ) ;
0 commit comments