Files
shields/services/maintenance/maintenance.spec.js
Caleb Cartwright 263e1be06d tests(Maintenance): refactor and test (#3305)
One of the tests for the Maintenance service that was added when the service was refactored is failing 
`AssertionError: message mismatch: expected 'no! (as of 2018)' to equal 'stale (as of 2019)'`

I believe the test was added in an attempt to cover the one of the code paths, but that original test would only pass a couple months out of the year. 

Testing those paths with the original implementation would have required a lot of stubbing clocks/timers, so instead I refactored the code a bit. I removed the flaky live/service test, and added some unit tests instead (which made more sense to me since this service badge doesn't hit a live endpoint)
2019-04-15 12:47:06 -04:00

66 lines
1.4 KiB
JavaScript

'use strict'
const { test, given } = require('sazerac')
const Maintenance = require('./maintenance.service')
describe('Maintenance', function() {
test(Maintenance.prototype.transform, () => {
given({
maintained: 'no',
currentYear: 2017,
year: 2018,
}).expect({
isMaintained: false,
targetYear: 2018,
})
given({
maintained: 'yes',
year: 2020,
currentYear: 2019,
}).expect({
isMaintained: true,
})
given({
maintained: 'yes',
year: 2018,
currentYear: 2019,
month: 2,
}).expect({
isStale: true,
targetYear: 2019,
})
given({
maintained: 'yes',
year: 2018,
currentYear: 2019,
month: 3,
}).expect({
isMaintained: false,
targetYear: 2018,
})
given({
maintained: 'yes',
year: 2018,
currentYear: 2020,
}).expect({
isMaintained: false,
targetYear: 2018,
})
})
test(Maintenance.render, () => {
given({ isMaintained: true, message: 'yes' }).expect({
message: 'yes',
color: 'brightgreen',
})
given({ isMaintained: false, targetYear: 2018 }).expect({
message: 'no! (as of 2018)',
color: 'red',
})
given({ isMaintained: false, isStale: true, targetYear: 2018 }).expect({
message: 'stale (as of 2018)',
color: undefined,
})
})
})