Files
shields/service-tests/hexpm.js
Pyves 81b9f6ac53 [dotnetstatus github gratipay hexpm wordpress] General test improvements (#1177)
* Extended usage of the metric validators
* Fixed incorrect Worldpress test data
* Removed usages of Joi.equal for bare string literals
* Switched to proper star formatting and made tests more robust
* Removed debug
2017-10-15 16:58:54 -04:00

46 lines
1.3 KiB
JavaScript

'use strict';
const Joi = require('joi');
const ServiceTester = require('./runner/service-tester');
const {
isMetric,
isMetricOverTimePeriod
} = require('./helpers/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' });