fix [GitHubHacktoberfest] service test (#4299)
* tests: fix hacktoberfest service test * tests: update message for post-hacktoberfest, add couple unit tests * chore: lgtm fix * tests: fix unit test
This commit is contained in:
@@ -84,7 +84,6 @@ When adding or changing a service [please add tests][service-tests].
|
||||
This project has quite a backlog of suggestions! If you're new to the project,
|
||||
maybe you'd like to open a pull request to address one of them:
|
||||
|
||||
[](https://github.com/badges/shields/issues?q=is%3Aopen+is%3Aissue+label%3Ahacktoberfest)
|
||||
[](https://github.com/badges/shields/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
|
||||
|
||||
You can read a [tutorial on how to add a badge][tutorial].
|
||||
|
||||
@@ -120,7 +120,14 @@ module.exports = class GithubHacktoberfestCombinedStatus extends GithubAuthV4Ser
|
||||
// We want to show "1 day left" on the last day so we add 1.
|
||||
daysLeft = moment('2019-11-01 12:00:00 Z').diff(moment(), 'days') + 1
|
||||
}
|
||||
|
||||
if (daysLeft < 0) {
|
||||
return {
|
||||
message: `is over! (${metric(contributionCount)} ${maybePluralize(
|
||||
'PR',
|
||||
contributionCount
|
||||
)} opened)`,
|
||||
}
|
||||
}
|
||||
const message =
|
||||
[
|
||||
suggestedIssueCount
|
||||
@@ -140,7 +147,7 @@ module.exports = class GithubHacktoberfestCombinedStatus extends GithubAuthV4Ser
|
||||
: '',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(', ') || 'is done!'
|
||||
.join(', ') || 'is over!'
|
||||
|
||||
return { message }
|
||||
}
|
||||
|
||||
22
services/github/github-hacktoberfest.spec.js
Normal file
22
services/github/github-hacktoberfest.spec.js
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict'
|
||||
|
||||
const { test, given } = require('sazerac')
|
||||
const GitHubHacktoberfest = require('./github-hacktoberfest.service')
|
||||
|
||||
describe('GitHubHacktoberfest', function() {
|
||||
test(GitHubHacktoberfest.render, () => {
|
||||
given({
|
||||
daysLeft: -1,
|
||||
contributionCount: 12,
|
||||
}).expect({
|
||||
message: 'is over! (12 PRs opened)',
|
||||
})
|
||||
given({
|
||||
daysLeft: 10,
|
||||
contributionCount: 27,
|
||||
suggestedIssueCount: 54,
|
||||
}).expect({
|
||||
message: '54 open issues, 27 PRs, 10 days left',
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -3,15 +3,27 @@
|
||||
const Joi = require('@hapi/joi')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
const isHactoberfestCombinedStatus = Joi.string().regex(
|
||||
const isHacktoberfestNoIssuesStatus = Joi.string().regex(
|
||||
/^[0-9]+ PRs?(, [0-9]+ days? left)?$/
|
||||
)
|
||||
const isHacktoberfestNoPRsStatus = Joi.string().regex(
|
||||
/^([0-9]+ open issues?)?[0-9]+ days? left$/
|
||||
)
|
||||
const isHacktoberfestCombinedStatus = Joi.string().regex(
|
||||
/^[0-9]+ open issues?(, [0-9]+ PRs?)?(, [0-9]+ days? left)?$/
|
||||
)
|
||||
const isHacktoberfestStatus = Joi.alternatives().try(
|
||||
isHacktoberfestNoIssuesStatus,
|
||||
isHacktoberfestNoPRsStatus,
|
||||
isHacktoberfestCombinedStatus,
|
||||
/^is over! \([0-9]+ PRs? opened\)$/
|
||||
)
|
||||
|
||||
t.create('GitHub Hacktoberfest combined status')
|
||||
.get('/badges/shields.json')
|
||||
.expectBadge({
|
||||
label: 'hacktoberfest',
|
||||
message: isHactoberfestCombinedStatus,
|
||||
message: isHacktoberfestStatus,
|
||||
})
|
||||
|
||||
t.create('GitHub Hacktoberfest combined status (suggestion label override)')
|
||||
@@ -22,5 +34,5 @@ t.create('GitHub Hacktoberfest combined status (suggestion label override)')
|
||||
)
|
||||
.expectBadge({
|
||||
label: 'hacktoberfest',
|
||||
message: isHactoberfestCombinedStatus,
|
||||
message: isHacktoberfestStatus,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user