Files
shields/services/hexpm/hexpm.tester.js
Paul Melnikow 7a664ca3e8 Run prettier (#1866)
Merging this separately so the commit with the tooling change is readable. This is a follow-on to #1167 which turned prettier on.
2018-08-08 17:57:14 -04:00

49 lines
1.3 KiB
JavaScript

'use strict'
const Joi = require('joi')
const ServiceTester = require('../service-tester')
const { isMetric, isMetricOverTimePeriod } = require('../test-validators')
const isHexpmVersion = Joi.string().regex(/^v\d+.\d+.?\d?$/)
const t = new ServiceTester({ id: 'hexpm', title: 'Hex.pm' })
module.exports = t
t.create('downloads per week')
.get('/dw/cowboy.json')
.expectJSONTypes(
Joi.object().keys({ name: 'downloads', value: isMetricOverTimePeriod })
)
t.create('downloads per day')
.get('/dd/cowboy.json')
.expectJSONTypes(
Joi.object().keys({ name: 'downloads', value: isMetricOverTimePeriod })
)
t.create('downloads in total')
.get('/dt/cowboy.json')
.expectJSONTypes(Joi.object().keys({ name: 'downloads', value: isMetric }))
t.create('version')
.get('/v/cowboy.json')
.expectJSONTypes(Joi.object().keys({ name: 'hex', value: isHexpmVersion }))
t.create('license')
.get('/l/cowboy.json')
.expectJSONTypes(
Joi.object().keys({
name: 'license',
value: Joi.string().required(),
})
)
t.create('unknown repo')
.get('/l/this-repo-does-not-exist.json')
.expectJSON({ name: 'hex', value: 'invalid' })
t.create('connection error')
.get('/l/cowboy.json')
.networkOff()
.expectJSON({ name: 'hex', value: 'inaccessible' })