Files
shields/services/github/github-actions-workflow-status.tester.js
T
chris48sGitHubrepo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
6049ef64c8 handle workflow runs that do not have a conclusion (#8717)
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2022-12-15 22:41:33 +00:00

86 lines
2.1 KiB
JavaScript

import Joi from 'joi'
import { isBuildStatus } from '../build-status.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
const isWorkflowStatus = Joi.alternatives()
.try(isBuildStatus, Joi.equal('no status'))
.required()
t.create('missing branch param')
.get('/actions/toolkit/unit-tests.yml.json')
.expectBadge({
label: 'build',
message: 'invalid query parameter: branch',
})
t.create('nonexistent repo')
.get('/badges/shields-fakeness/fake.yml.json?branch=main')
.expectBadge({
label: 'build',
message: 'repo or workflow not found',
})
t.create('nonexistent workflow')
.get('/actions/toolkit/not-a-real-workflow.yml.json?branch=main')
.expectBadge({
label: 'build',
message: 'repo or workflow not found',
})
t.create('nonexistent branch')
.get('/actions/toolkit/unit-tests.yml.json?branch=not-a-real-branch')
.expectBadge({
label: 'build',
message: 'branch or event not found',
})
t.create('nonexistent event')
.get(
'/actions/toolkit/unit-tests.yml.json?branch=main&event=not-a-real-event'
)
.expectBadge({
label: 'build',
message: 'branch or event not found',
})
t.create('valid workflow')
.get('/actions/toolkit/unit-tests.yml.json?branch=main')
.expectBadge({
label: 'build',
message: isWorkflowStatus,
})
t.create('valid workflow (with event)')
.get('/actions/toolkit/unit-tests.yml.json?branch=main&event=push')
.expectBadge({
label: 'build',
message: isWorkflowStatus,
})
t.create('workflow in progress')
.get('/actions/toolkit/unit-tests.yml.json?branch=main')
.intercept(nock =>
nock('https://api.github.com')
.get('/repos/actions/toolkit/actions/workflows/unit-tests.yml/runs')
.query({
branch: 'main',
page: '1',
per_page: '1',
exclude_pull_requests: 'true',
})
.reply(200, {
workflow_runs: [
{
status: 'in_progress',
conclusion: null,
},
],
})
)
.expectBadge({
label: 'build',
message: 'in progress',
color: 'lightgrey',
})