Remove legacy helper makeBadgeData (#3392)

Close #3369
This commit is contained in:
Paul Melnikow
2019-04-29 19:44:25 -04:00
committed by GitHub
parent b752bbfd5a
commit b2e21da34d
6 changed files with 49 additions and 121 deletions

View File

@@ -1,53 +0,0 @@
'use strict'
const coalesce = require('../core/base-service/coalesce')
const toArray = require('../core/base-service/to-array')
const { makeLogo } = require('./logos')
function makeLabel(defaultLabel, overrides) {
return `${
overrides.label === undefined
? (defaultLabel || '').toLowerCase()
: overrides.label
}`
}
// Generate the initial badge data. Pass the URL query parameters, which
// override the default label.
//
// The following parameters are supported:
//
// - label
// - style
// - logo
// - logoWidth
// - link
// - color and colorB
// - labelColor and colorA
// - maxAge
// - cacheSeconds
//
// Note: `maxAge` and `cacheSeconds` are handled by cache(), not this function.
function makeBadgeData(defaultLabel, overrides) {
const colorA = coalesce(overrides.labelColor, overrides.colorA)
const colorB = coalesce(overrides.color, overrides.colorB)
return {
text: [makeLabel(defaultLabel, overrides), 'n/a'],
colorscheme: 'lightgrey',
template: overrides.style,
logo: makeLogo(undefined, overrides),
logoPosition: +overrides.logoPosition,
logoWidth: +overrides.logoWidth,
links: toArray(overrides.link),
// Scoutcamp sometimes turns these into numbers.
colorA: typeof colorA === 'number' ? `${colorA}` : colorA,
colorB: typeof colorB === 'number' ? `${colorB}` : colorB,
}
}
module.exports = {
toArray,
makeLabel,
makeBadgeData,
}

View File

@@ -1,39 +0,0 @@
'use strict'
const { test, given } = require('sazerac')
const { makeLabel, makeBadgeData } = require('./badge-data')
describe('Badge data helpers', function() {
test(makeLabel, () => {
given('my badge', {}).expect('my badge')
given('My bAdge', {}).expect('my badge')
given('my badge', { label: 'no, my badge' }).expect('no, my badge')
given('my badge', { label: 'no, MY badge' }).expect('no, MY badge')
given('my badge', { label: false }).expect('false')
given('my badge', { label: 0 }).expect('0')
given('my badge', { label: '' }).expect('')
})
test(makeBadgeData, () => {
given('my badge', {
label: 'no, my badge',
style: 'flat-square',
logo: 'image/svg+xml;base64,PHN2ZyB4bWxu',
logoPosition: 10,
logoWidth: '25',
link: 'https://example.com/',
colorA: 'blue',
colorB: 'f00bae',
}).expect({
text: ['no, my badge', 'n/a'],
colorscheme: 'lightgrey',
template: 'flat-square',
logo: 'data:image/svg+xml;base64,PHN2ZyB4bWxu',
logoPosition: 10,
logoWidth: 25,
links: ['https://example.com/'],
colorA: 'blue',
colorB: 'f00bae',
})
})
})