@@ -62,7 +62,7 @@ describe('BaseCommand', () => {
6262 } ) ;
6363
6464 describe ( 'constructor' , ( ) => {
65- it ( 'stores PromptManager and RequestManager correctly ' , ( ) => {
65+ it ( 'should store PromptManager and RequestManager instances ' , ( ) => {
6666 // @ts -expect-error Access to protected property for a test
6767 expect ( command . promptManager ) . toBe ( promptManager ) ;
6868 // @ts -expect-error Access to protected property for a test
@@ -71,7 +71,7 @@ describe('BaseCommand', () => {
7171 } ) ;
7272
7373 describe ( 'execute' , ( ) => {
74- it ( 'getTemplateName returns value correctly ' , ( ) => {
74+ it ( 'getTemplateName should return the name of the corresponding template ' , ( ) => {
7575 const spy = jest . spyOn ( command , 'getTemplateName' ) ;
7676
7777 command . execute ( params , { } ) ;
@@ -80,7 +80,7 @@ describe('BaseCommand', () => {
8080 expect ( spy ) . toHaveReturnedWith ( 'test-template-name' ) ;
8181 } ) ;
8282
83- it ( 'buildPromptData receives and returns correct data' , ( ) => {
83+ it ( 'buildPromptData should receive and returns correct data' , ( ) => {
8484 const spy = jest . spyOn ( command , 'buildPromptData' ) ;
8585
8686 command . execute ( params , { } ) ;
@@ -93,7 +93,7 @@ describe('BaseCommand', () => {
9393 } ) ;
9494 } ) ;
9595
96- it ( 'parseResult receives correct value and returns expected result' , async ( ) => {
96+ it ( 'parseResult should receive correct value and return expected result' , async ( ) => {
9797 const spy = jest . spyOn ( command , 'parseResult' ) ;
9898
9999 command . execute ( params , { } ) ;
@@ -105,14 +105,14 @@ describe('BaseCommand', () => {
105105 expect ( spy ) . toHaveReturnedWith ( 'Parsed result: AI response' ) ;
106106 } ) ;
107107
108- it ( 'callbacks are called correctly ' , async ( ) => {
109- const callbacks = {
108+ it ( 'callbacks should be called a specified number of times ' , async ( ) => {
109+ const callbacks : RequestCallbacks < unknown > = {
110110 onComplete : jest . fn ( ) ,
111111 onError : jest . fn ( ) ,
112112 onChunk : jest . fn ( ) ,
113113 } ;
114114
115- command . execute ( params , callbacks as RequestCallbacks ) ;
115+ command . execute ( params , callbacks ) ;
116116
117117 await new Promise ( process . nextTick ) ;
118118
@@ -121,44 +121,46 @@ describe('BaseCommand', () => {
121121 expect ( callbacks . onChunk ) . toHaveBeenCalledTimes ( 2 ) ;
122122 } ) ;
123123
124- it ( 'onComplete is called with parseResult output' , async ( ) => {
125- const callbacks = { onComplete : jest . fn ( ) } ;
124+ it ( 'onComplete should be called with parseResult output' , async ( ) => {
125+ const callbacks : RequestCallbacks < unknown > = { onComplete : jest . fn ( ) } ;
126126
127- command . execute ( params , callbacks as RequestCallbacks ) ;
127+ command . execute ( params , callbacks ) ;
128128
129129 await new Promise ( process . nextTick ) ;
130130
131131 expect ( callbacks . onComplete ) . toHaveBeenCalledWith ( 'Parsed result: AI response' ) ;
132132 } ) ;
133133
134- it ( 'calls onError if request fails' , async ( ) => {
135- const originalSendRequest = requestManager . sendRequest ;
136-
137- requestManager . sendRequest = ( _ , callbacks ) => {
138- callbacks . onError ?.( new Error ( 'Test error' ) ) ;
134+ describe ( 'if request fails' , ( ) => {
135+ it ( 'should call onError ' , async ( ) => {
136+ const originalSendRequest = requestManager . sendRequest ;
139137
140- return ( ) : void => { } ;
141- } ;
138+ requestManager . sendRequest = ( _ , callbacks ) => {
139+ callbacks . onError ?. ( new Error ( 'Test error' ) ) ;
142140
143- try {
144- const callbacks = {
145- onError : jest . fn ( ) ,
146- onComplete : jest . fn ( ) ,
141+ return ( ) : void => { } ;
147142 } ;
148143
149- command . execute ( params , callbacks as RequestCallbacks ) ;
144+ try {
145+ const callbacks : RequestCallbacks < unknown > = {
146+ onError : jest . fn ( ) ,
147+ onComplete : jest . fn ( ) ,
148+ } ;
150149
151- await new Promise ( process . nextTick ) ;
150+ command . execute ( params , callbacks ) ;
152151
153- expect ( callbacks . onError ) . toHaveBeenCalledTimes ( 1 ) ;
154- expect ( callbacks . onError ) . toHaveBeenCalledWith ( new Error ( 'Test error' ) ) ;
155- expect ( callbacks . onComplete ) . toHaveBeenCalledTimes ( 0 ) ;
156- } finally {
157- requestManager . sendRequest = originalSendRequest ;
158- }
152+ await new Promise ( process . nextTick ) ;
153+
154+ expect ( callbacks . onError ) . toHaveBeenCalledTimes ( 1 ) ;
155+ expect ( callbacks . onError ) . toHaveBeenCalledWith ( new Error ( 'Test error' ) ) ;
156+ expect ( callbacks . onComplete ) . toHaveBeenCalledTimes ( 0 ) ;
157+ } finally {
158+ requestManager . sendRequest = originalSendRequest ;
159+ }
160+ } ) ;
159161 } ) ;
160162
161- it ( 'calls onChunk for each chunk and onComplete correctly ' , ( ) => {
163+ it ( 'should call onChunk for each chunk and onComplete a specified number of times with expected params ' , ( ) => {
162164 const originalSendRequest = requestManager . sendRequest ;
163165
164166 requestManager . sendRequest = ( _ , callbacks ) => {
@@ -185,7 +187,7 @@ describe('BaseCommand', () => {
185187 }
186188 } ) ;
187189
188- it ( 'executes with undefined params without errors' , async ( ) => {
190+ it ( 'should execute with undefined params without errors' , async ( ) => {
189191 const sendRequestSpy = jest . spyOn ( requestManager , 'sendRequest' ) ;
190192 const onError = jest . fn ( ) ;
191193
@@ -197,7 +199,7 @@ describe('BaseCommand', () => {
197199 expect ( sendRequestSpy ) . toHaveBeenCalledTimes ( 1 ) ;
198200 } ) ;
199201
200- it ( 'executes with partial callbacks without errors' , async ( ) => {
202+ it ( 'should execute with partial callbacks without errors' , async ( ) => {
201203 const sendRequestSpy = jest . spyOn ( requestManager , 'sendRequest' ) ;
202204 const callbacks = { onChunk : jest . fn ( ) } ;
203205
@@ -209,12 +211,12 @@ describe('BaseCommand', () => {
209211 expect ( sendRequestSpy ) . toHaveBeenCalledTimes ( 1 ) ;
210212 } ) ;
211213
212- it ( 'executes with undefined callbacks without errors' , ( ) => {
214+ it ( 'should execute with undefined callbacks without errors' , ( ) => {
213215 const sendRequestSpy = jest . spyOn ( requestManager , 'sendRequest' ) ;
214216
215217 expect ( command . execute (
216218 params ,
217- ( undefined as unknown as RequestCallbacks ) ,
219+ ( undefined as unknown as RequestCallbacks < unknown > ) ,
218220 ) ) . not . toThrow ( ) ;
219221
220222 expect ( sendRequestSpy ) . toHaveBeenCalledTimes ( 1 ) ;
0 commit comments