Files
shields/service-tests/amo.js
Paul Melnikow c3636e7549 Clean up service tests (#1127)
- Consolidate regexes
- Use slimmer syntax where possible
- Fix bug caught by failing amo tests
2017-10-09 14:41:18 -04:00

58 lines
1.5 KiB
JavaScript

'use strict';
const Joi = require('joi');
const ServiceTester = require('./runner/service-tester');
const {
isMetric,
isStarRating,
isVPlusDottedVersionAtLeastOne,
} = require('./helpers/validators');
const t = new ServiceTester({ id: 'amo', title: 'Mozilla Addons' });
module.exports = t;
t.create('Downloads')
.get('/d/IndieGala-Helper.json')
.expectJSONTypes(Joi.object().keys({ name: 'downloads', value: isMetric }));
t.create('Version')
.get('/v/IndieGala-Helper.json')
.expectJSONTypes(Joi.object().keys({
name: 'mozilla add-on',
value: isVPlusDottedVersionAtLeastOne
}));
t.create('Version - Custom label')
.get('/v/IndieGala-Helper.json?label=IndieGala Helper')
.expectJSONTypes(Joi.object().keys({
name: 'IndieGala Helper',
value: isVPlusDottedVersionAtLeastOne
}));
t.create('Users')
.get('/users/IndieGala-Helper.json')
.expectJSONTypes(Joi.object().keys({
name: 'users',
value: Joi.string().regex(/^\d+$/)
}));
t.create('Rating')
.get('/rating/IndieGala-Helper.json')
.expectJSONTypes(Joi.object().keys({
name: 'rating',
value: Joi.string().regex(/^\d\/\d$/)
}));
t.create('Stars')
.get('/stars/IndieGala-Helper.json')
.expectJSONTypes(Joi.object().keys({ name: 'stars', value: isStarRating }));
t.create('Invalid addon')
.get('/d/invalid-name-of-addon.json')
.expectJSON({ name: 'mozilla add-on', value: 'invalid' });
t.create('No connection')
.get('/v/IndieGala-Helper.json')
.networkOff()
.expectJSON({ name: 'mozilla add-on', value: 'inaccessible' });