Skip to content

Commit

Permalink
Support style
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmelnikow committed Jan 15, 2019
1 parent bfd8243 commit ae129af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion services/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const serviceDataSchema = Joi.object({
// Generally services should not use these options, which are provided to
// support the Endpoint badge.
labelColor: Joi.string(),
style: Joi.string(),
}).required()

class BaseService {
Expand Down Expand Up @@ -330,7 +331,7 @@ class BaseService {

static _makeBadgeData(overrides, serviceData) {
const {
style,
style: overrideStyle,
label: overrideLabel,
logo: overrideLogo,
logoColor: overrideLogoColor,
Expand All @@ -347,6 +348,7 @@ class BaseService {
color: serviceColor,
labelColor: serviceLabelColor,
link: serviceLink,
style: serviceStyle,
} = serviceData

const {
Expand All @@ -370,6 +372,8 @@ class BaseService {
)
}

const style = coalesce(overrideStyle, serviceStyle)

const badgeData = {
text: [
// Use `coalesce()` to support empty labels and messages, as in the
Expand Down
1 change: 1 addition & 0 deletions services/endpoint/endpoint.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ module.exports = class Endpoint extends BaseJsonService {
message,
color,
labelColor,
style,
}
}

Expand Down
21 changes: 21 additions & 0 deletions services/endpoint/endpoint.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ t.create('color and labelColor')
colorA: '#e6e6fa',
})

t.create('style')
.get('.json?url=https://example.com/badge')
.only()
.intercept(nock =>
nock('https://example.com/')
.get('/badge')
.reply(200, {
schemaVersion: 1,
label: 'hey',
message: 'yo',
color: '#99c',
style: '_shields_test',
})
)
.expectJSON({
name: 'hey',
value: 'yo',
// colorB is only in _shields_test which is being specified by the service.
colorB: '#99c',
})

t.create('Invalid schema (mocked)')
.get('.json?url=https://example.com/badge')
.intercept(nock =>
Expand Down

0 comments on commit ae129af

Please sign in to comment.