Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce boilerplate in a few more service testers [cdnjs continuousphp node shippable wercker gem] #1957

Merged
merged 7 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions services/cdnjs/cdnjs.tester.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict'

const Joi = require('joi')
const ServiceTester = require('../service-tester')
const createServiceTester = require('../create-service-tester')
const { isVPlusTripleDottedVersion } = require('../test-validators')

const t = new ServiceTester({ id: 'cdnjs', title: 'CDNJs' })
const t = createServiceTester()
module.exports = t

t.create('cdnjs (valid)')
.get('/v/jquery.json')
.get('/jquery.json')
.expectJSONTypes(
Joi.object().keys({
name: 'cdnjs',
Expand All @@ -17,5 +17,5 @@ t.create('cdnjs (valid)')
)

t.create('cdnjs (not found)')
.get('/v/not-a-library.json')
.get('/not-a-library.json')
.expectJSON({ name: 'cdnjs', value: 'not found' })
4 changes: 4 additions & 0 deletions services/continuousphp/continuousphp.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const LegacyService = require('../legacy-service')
const { makeBadgeData: getBadgeData } = require('../../lib/badge-data')

module.exports = class ContinuousPhp extends LegacyService {
static get url() {
return { base: 'continuousphp' }
}

static registerLegacyRouteHandler({ camp, cache }) {
camp.route(
/^\/continuousphp\/([^/]+)\/([^/]+\/[^/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/,
Expand Down
4 changes: 2 additions & 2 deletions services/continuousphp/continuousphp.tester.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const Joi = require('joi')
const ServiceTester = require('../service-tester')
const createServiceTester = require('../create-service-tester')
const { isBuildStatus } = require('../test-validators')

const t = new ServiceTester({ id: 'continuousphp', title: 'continuousphp' })
const t = createServiceTester()
module.exports = t

t.create('build status on default branch')
Expand Down
8 changes: 2 additions & 6 deletions services/gem/gem-downloads.tester.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
'use strict'

const Joi = require('joi')
const ServiceTester = require('../service-tester')
const createServiceTester = require('../create-service-tester')

const { isMetric } = require('../test-validators')

const t = new ServiceTester({
id: 'gem-downloads',
title: 'Ruby Gem Downloads',
pathPrefix: '/gem',
})
const t = createServiceTester()
module.exports = t

// total downloads
Expand Down
16 changes: 8 additions & 8 deletions services/node/node.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,51 @@

const { expect } = require('chai')
const Joi = require('joi')
const ServiceTester = require('../service-tester')
const createServiceTester = require('../create-service-tester')
const { Range } = require('semver')

const t = new ServiceTester({ id: 'node', title: 'Node' })
const t = createServiceTester()
module.exports = t

function expectSemverRange(value) {
expect(() => new Range(value)).not.to.throw()
}

t.create('gets the node version of passport')
.get('/v/passport.json')
.get('/passport.json')
.expectJSONTypes(Joi.object({ name: 'node' }).unknown())
.afterJSON(json => {
expectSemverRange(json.value)
})

t.create('gets the node version of @stdlib/stdlib')
.get('/v/@stdlib/stdlib.json')
.get('/@stdlib/stdlib.json')
.expectJSONTypes(Joi.object({ name: 'node' }).unknown())
.afterJSON(json => {
expectSemverRange(json.value)
})

t.create("gets the tagged release's node version version of ionic")
.get('/v/ionic/next.json')
.get('/ionic/next.json')
.expectJSONTypes(Joi.object({ name: 'node@next' }).unknown())
.afterJSON(json => {
expectSemverRange(json.value)
})

t.create('gets the node version of passport from a custom registry')
.get('/v/passport.json?registry_uri=https://registry.npmjs.com')
.get('/passport.json?registry_uri=https://registry.npmjs.com')
.expectJSONTypes(Joi.object({ name: 'node' }).unknown())
.afterJSON(json => {
expectSemverRange(json.value)
})

t.create("gets the tagged release's node version of @cycle/core")
.get('/v/@cycle/core/canary.json')
.get('/@cycle/core/canary.json')
.expectJSONTypes(Joi.object({ name: 'node@canary' }).unknown())
.afterJSON(json => {
expectSemverRange(json.value)
})

t.create('invalid package name')
.get('/v/frodo-is-not-a-package.json')
.get('/frodo-is-not-a-package.json')
.expectJSON({ name: 'node', value: 'package not found' })
4 changes: 2 additions & 2 deletions services/shippable/shippable.tester.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict'

const Joi = require('joi')
const ServiceTester = require('../service-tester')
const createServiceTester = require('../create-service-tester')
const { invalidJSON } = require('../response-fixtures')
const { isBuildStatus } = require('../test-validators')

const t = new ServiceTester({ id: 'shippable', title: 'Shippable CI' })
const t = createServiceTester()
module.exports = t

t.create('build status (valid, without branch)')
Expand Down
14 changes: 7 additions & 7 deletions services/wercker/wercker.tester.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
'use strict'

const Joi = require('joi')
const ServiceTester = require('../service-tester')
const createServiceTester = require('../create-service-tester')

const { isBuildStatus } = require('../test-validators')

const t = new ServiceTester({ id: 'wercker', title: 'Wercker' })
const t = createServiceTester()
module.exports = t

t.create('CI build status')
.get('/ci/wercker/go-wercker-api.json')
.get('/wercker/go-wercker-api.json')
.expectJSONTypes(Joi.object().keys({ name: 'build', value: isBuildStatus }))

t.create('CI build status (branch)')
.get('/ci/wercker/go-wercker-api/master.json')
.get('/wercker/go-wercker-api/master.json')
.expectJSONTypes(Joi.object().keys({ name: 'build', value: isBuildStatus }))

t.create('CI build status (old v1 API)')
.get('/ci/559e33c8e982fc615500b357.json')
.get('/559e33c8e982fc615500b357.json')
.expectJSONTypes(Joi.object().keys({ name: 'build', value: isBuildStatus }))

t.create('CI application not found')
.get('/ci/somerandomproject/thatdoesntexits.json')
.get('/somerandomproject/thatdoesntexits.json')
.expectJSON({ name: 'build', value: 'application not found' })

t.create('CI private application')
.get('/ci/wercker/blueprint.json')
.get('/wercker/blueprint.json')
.expectJSON({ name: 'build', value: 'private application not supported' })