Skip to content

Commit 10bff68

Browse files
(feat): Add safe-guard against a 200 response from createWorkflowDispatch
1 parent 51f9a49 commit 10bff68

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/api/api.test.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,32 @@ describe('API', () => {
8585
init(mockActionConfig)
8686
})
8787

88-
it('should resolve after a successful dispatch', async () => {
88+
// GitHub released a breaking change to the createWorkflowDispatch API that resulted in a change where the returned
89+
// status code changed to 200, from 204.
90+
//
91+
// Given that we are in an interim state where the API behaviour, but the public documentation has not been updated
92+
// to reflect this change, and GitHub has not yet released any updates on this topic. I can going to play the safe
93+
// route and assume that the response status code could be either 200 or 204. I've added a test case that supports both
94+
// potential status codes.
95+
//
96+
// Reference: https://github.com/orgs/community/discussions/9752#discussioncomment-15295321
97+
// Documentation: https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event
98+
it('should resolve after a successful dispatch with a 200 status', async () => {
99+
jest
100+
.spyOn(mockOctokit.rest.actions, 'createWorkflowDispatch')
101+
.mockReturnValue(
102+
Promise.resolve({
103+
headers: null,
104+
url: '',
105+
data: undefined,
106+
status: 200
107+
})
108+
)
109+
110+
await workflowDispatch('')
111+
})
112+
113+
it('should resolve after a successful dispatch with a 204 status', async () => {
89114
jest
90115
.spyOn(mockOctokit.rest.actions, 'createWorkflowDispatch')
91116
.mockReturnValue(
@@ -112,7 +137,7 @@ describe('API', () => {
112137
)
113138

114139
await expect(workflowDispatch('')).rejects.toThrow(
115-
`Failed to dispatch action, expected 204 but received ${errorStatus}`
140+
`Failed to dispatch action, expected 200 or 204 but received ${errorStatus}`
116141
)
117142
})
118143

@@ -126,7 +151,7 @@ describe('API', () => {
126151

127152
return {
128153
data: undefined,
129-
status: 204
154+
status: 200
130155
}
131156
})
132157

@@ -147,7 +172,7 @@ describe('API', () => {
147172

148173
return {
149174
data: undefined,
150-
status: 204
175+
status: 200
151176
}
152177
})
153178

0 commit comments

Comments
 (0)