Skip to content

Commit 8b0625a

Browse files
committed
Improve deployment request test coverage
1 parent cd2ce8f commit 8b0625a

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

‎src/__tests__/internal/deployment.test.js‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,58 @@ describe('Deployment', () => {
121121
twirpScope.done()
122122
})
123123

124+
it('can successfully create a deployment with a 64-character build version', async () => {
125+
process.env.GITHUB_SHA = 'a'.repeat(64)
126+
127+
const twirpScope = nock(process.env.ACTIONS_RESULTS_URL)
128+
.post(LIST_ARTIFACTS_TWIRP_PATH)
129+
.reply(
130+
200,
131+
{
132+
artifacts: [{ databaseId: 11, name: 'github-pages', size: 221 }]
133+
},
134+
{ headers: { 'content-type': 'application/json' } }
135+
)
136+
137+
mockPool
138+
.intercept({
139+
path: `/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`,
140+
method: 'POST',
141+
body: bodyString => {
142+
const body = JSON.parse(bodyString)
143+
const keys = Object.keys(body).sort()
144+
return (
145+
keys.length === 3 &&
146+
keys[0] === 'artifact_id' &&
147+
keys[1] === 'oidc_token' &&
148+
keys[2] === 'pages_build_version' &&
149+
body.artifact_id === 11 &&
150+
body.pages_build_version === process.env.GITHUB_SHA &&
151+
body.oidc_token === fakeJwt
152+
)
153+
}
154+
})
155+
.reply(
156+
200,
157+
{
158+
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
159+
page_url: 'https://actions.github.io/is-awesome'
160+
},
161+
{ headers: { 'content-type': 'application/json' } }
162+
)
163+
164+
const deployment = new Deployment()
165+
await deployment.create(fakeJwt)
166+
167+
expect(process.env.GITHUB_SHA).toHaveLength(64)
168+
expect(core.setFailed).not.toHaveBeenCalled()
169+
expect(core.info).toHaveBeenLastCalledWith(
170+
expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`))
171+
)
172+
173+
twirpScope.done()
174+
})
175+
124176
it('can successfully create a preview deployment', async () => {
125177
process.env.GITHUB_SHA = 'valid-build-version'
126178

0 commit comments

Comments
 (0)