@@ -145,7 +145,7 @@ describe("API", () => {
145145 ` ) ;
146146 } ) ;
147147
148- it ( "should throw if a non-204 status is returned" , async ( ) => {
148+ it ( "should throw if a non-200 or non- 204 status is returned" , async ( ) => {
149149 const errorStatus = 401 ;
150150 vi . spyOn (
151151 mockOctokit . rest . actions ,
@@ -160,52 +160,53 @@ describe("API", () => {
160160
161161 // Behaviour
162162 await expect ( dispatchWorkflow ( "" ) ) . rejects . toThrow (
163- `Failed to dispatch action, expected 204 but received ${ errorStatus } ` ,
163+ `Failed to dispatch action, expected 200 or 204 but received ${ errorStatus } ` ,
164164 ) ;
165165
166166 // Logging
167167 assertOnlyCalled ( coreErrorLogMock , coreDebugLogMock ) ;
168168 expect ( coreErrorLogMock ) . toHaveBeenCalledOnce ( ) ;
169169 expect ( coreErrorLogMock . mock . calls [ 0 ] ?. [ 0 ] ) . toMatchInlineSnapshot (
170- `"dispatchWorkflow: An unexpected error has occurred: Failed to dispatch action, expected 204 but received 401"` ,
170+ `"dispatchWorkflow: An unexpected error has occurred: Failed to dispatch action, expected 200 or 204 but received 401"` ,
171171 ) ;
172172 expect ( coreDebugLogMock ) . toHaveBeenCalledOnce ( ) ;
173173 } ) ;
174174
175- it ( "should dispatch with a distinctId in the inputs" , async ( ) => {
176- const distinctId = "50b4f5fa-f9ce-4661-80e6-6d660a4a3a0d" ;
177- let dispatchedId : string | undefined ;
178- vi . spyOn (
179- mockOctokit . rest . actions ,
180- "createWorkflowDispatch" ,
181- ) . mockImplementation ( ( req ?: any ) => {
182- dispatchedId = req . inputs . distinct_id ;
175+ it . each ( [ 200 , 204 ] ) (
176+ "should dispatch with a distinctId in the inputs and handle a %d response" ,
177+ async ( statusCode ) => {
178+ const distinctId = "50b4f5fa-f9ce-4661-80e6-6d660a4a3a0d" ;
179+ let dispatchedId : string | undefined ;
180+ vi . spyOn (
181+ mockOctokit . rest . actions ,
182+ "createWorkflowDispatch" ,
183+ ) . mockImplementation ( ( req ?: any ) => {
184+ dispatchedId = req . inputs . distinct_id ;
183185
184- return Promise . resolve ( {
185- data : undefined ,
186- status : 204 ,
187- headers : { } ,
186+ return Promise . resolve ( {
187+ data : undefined ,
188+ status : statusCode ,
189+ headers : { } ,
190+ } ) ;
188191 } ) ;
189- } ) ;
190192
191- // Behaviour
192- await expect ( dispatchWorkflow ( distinctId ) ) . resolves . not . toThrow ( ) ;
193- expect ( dispatchedId ) . toStrictEqual ( distinctId ) ;
194-
195- // Logging
196- assertOnlyCalled ( coreInfoLogMock ) ;
197- expect ( coreInfoLogMock ) . toHaveBeenCalledOnce ( ) ;
198- expect ( coreInfoLogMock . mock . calls [ 0 ] ?. [ 0 ] ) . toMatchInlineSnapshot (
199- `
200- "Successfully dispatched workflow:
201- Repository: owner/repo
202- Branch: ref
203- Workflow: workflow
204- Workflow Inputs: {"testInput":"test"}
205- Distinct ID: 50b4f5fa-f9ce-4661-80e6-6d660a4a3a0d"
206- ` ,
207- ) ;
208- } ) ;
193+ // Behaviour
194+ await expect ( dispatchWorkflow ( distinctId ) ) . resolves . not . toThrow ( ) ;
195+ expect ( dispatchedId ) . toStrictEqual ( distinctId ) ;
196+
197+ // Logging
198+ assertOnlyCalled ( coreInfoLogMock ) ;
199+ expect ( coreInfoLogMock ) . toHaveBeenCalledOnce ( ) ;
200+ expect ( coreInfoLogMock . mock . calls [ 0 ] ?. [ 0 ] ) . toMatch (
201+ "Successfully dispatched workflow:\n" +
202+ " Repository: owner/repo\n" +
203+ " Branch: ref\n" +
204+ " Workflow: workflow\n" +
205+ ' Workflow Inputs: {"testInput":"test"}\n' +
206+ " Distinct ID: 50b4f5fa-f9ce-4661-80e6-6d660a4a3a0d" ,
207+ ) ;
208+ } ,
209+ ) ;
209210 } ) ;
210211
211212 describe ( "fetchWorkflowId" , ( ) => {
0 commit comments