Rewrite deprecated services and add tests (#2018)
I've rewritten the deprecated services using the `deprecatedService` helper from #1922. I added a test for `Deprecated`, and for `enforceDeprecation`, which isn't being used right now, but is there for future use. This also makes it possible to write services using BaseService which do not have any named parameters (with a test). Ref: #1358
This commit is contained in:
@@ -1518,10 +1518,6 @@ const allBadgeExamples = [
|
||||
name: 'Other',
|
||||
},
|
||||
examples: [
|
||||
{
|
||||
title: 'VersionEye',
|
||||
previewUrl: '/versioneye/d/ruby/rails.svg',
|
||||
},
|
||||
{
|
||||
title: 'Wheelmap',
|
||||
previewUrl: '/wheelmap/a/2323004600.svg',
|
||||
|
||||
@@ -1,27 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const { makeBadgeData, setBadgeColor } = require('./badge-data')
|
||||
const { deprecatedServices } = require('./deprecated-services')
|
||||
const { Deprecated } = require('../services/errors')
|
||||
|
||||
const isDeprecated = function(
|
||||
service,
|
||||
now = new Date(),
|
||||
depServices = deprecatedServices
|
||||
) {
|
||||
if (!(service in depServices)) {
|
||||
return false
|
||||
}
|
||||
return now.getTime() >= depServices[service].getTime()
|
||||
}
|
||||
|
||||
const getDeprecatedBadge = function(label, data) {
|
||||
const badgeData = makeBadgeData(label, data)
|
||||
setBadgeColor(badgeData, 'lightgray')
|
||||
badgeData.text[1] = 'no longer available'
|
||||
return badgeData
|
||||
}
|
||||
|
||||
function enforceDeprecation(effectiveDate) {
|
||||
if (Date.now() >= effectiveDate.getTime()) {
|
||||
throw new Deprecated()
|
||||
@@ -29,7 +9,5 @@ function enforceDeprecation(effectiveDate) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isDeprecated,
|
||||
getDeprecatedBadge,
|
||||
enforceDeprecation,
|
||||
}
|
||||
|
||||
@@ -1,33 +1,17 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const { test, given } = require('sazerac')
|
||||
const { isDeprecated, getDeprecatedBadge } = require('./deprecation-helpers')
|
||||
const { Deprecated } = require('../services/errors')
|
||||
const { enforceDeprecation } = require('./deprecation-helpers')
|
||||
|
||||
describe('Deprecated Badge Helper', function() {
|
||||
it('makes "no longer available" badge', function() {
|
||||
const badge = getDeprecatedBadge('foo', {})
|
||||
expect(badge.text[0]).to.equal('foo')
|
||||
expect(badge.text[1]).to.equal('no longer available')
|
||||
expect(badge.colorscheme).to.equal('lightgray')
|
||||
describe('enforceDeprecation', function() {
|
||||
it('throws Deprecated for a date in the past', function() {
|
||||
expect(() => enforceDeprecation(new Date())).to.throw(Deprecated)
|
||||
})
|
||||
|
||||
it('ignores colorB param', function() {
|
||||
const badge = getDeprecatedBadge('foo', { colorB: 'fedcba' })
|
||||
expect(badge.colorscheme).to.equal('lightgray')
|
||||
})
|
||||
})
|
||||
|
||||
describe('isDeprecated function', function() {
|
||||
test(isDeprecated, function() {
|
||||
given('fooservice', new Date(), {}).expect(false)
|
||||
|
||||
given('fooservice', new Date('2001-01-11 23:59:00Z'), {
|
||||
fooservice: new Date('2001-01-12'),
|
||||
}).expect(false)
|
||||
|
||||
given('fooservice', new Date('2001-01-12 00:00:01Z'), {
|
||||
fooservice: new Date('2001-01-12'),
|
||||
}).expect(true)
|
||||
it('does not throw for a date in the future', function() {
|
||||
expect(() =>
|
||||
enforceDeprecation(new Date(Date.now() + 10000))
|
||||
).not.to.throw()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user