Clean up service tests (#1127)
- Consolidate regexes - Use slimmer syntax where possible - Fix bug caught by failing amo tests
This commit is contained in:
@@ -6180,19 +6180,19 @@ cache(function(query_data, match, sendBadge, request) {
|
||||
break;
|
||||
case 'rating':
|
||||
rating = parseInt(data.addon.rating, 10);
|
||||
badgeData.text[0] = getLabel('downloads', query_data);
|
||||
badgeData.text[0] = getLabel('rating', query_data);
|
||||
badgeData.text[1] = rating + '/5';
|
||||
badgeData.colorscheme = floorCountColor(rating, 2, 3, 4);
|
||||
break;
|
||||
case 'stars':
|
||||
rating = parseInt(data.addon.rating, 10);
|
||||
badgeData.text[0] = getLabel('downloads', query_data);
|
||||
badgeData.text[0] = getLabel('stars', query_data);
|
||||
badgeData.text[1] = starRating(rating);
|
||||
badgeData.colorscheme = floorCountColor(rating, 2, 3, 4);
|
||||
break;
|
||||
case 'users':
|
||||
var dailyUsers = parseInt(data.addon.daily_users[0], 10);
|
||||
badgeData.text[0] = getLabel('downloads', query_data);
|
||||
badgeData.text[0] = getLabel('users', query_data);
|
||||
badgeData.text[1] = metric(dailyUsers);
|
||||
badgeData.colorscheme = 'brightgreen';
|
||||
break;
|
||||
|
||||
@@ -123,7 +123,7 @@ Here's what our first test looks like:
|
||||
t.create('build status on default branch')
|
||||
.get('/rust-lang/rust.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('build'),
|
||||
name: 'build',
|
||||
value: Joi.equal('failing', 'passing', 'unknown')
|
||||
}));
|
||||
```
|
||||
|
||||
@@ -2,51 +2,50 @@
|
||||
|
||||
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: Joi.equal('downloads'),
|
||||
value: Joi.string().regex(/^\d+k$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'downloads', value: isMetric }));
|
||||
|
||||
t.create('Version')
|
||||
.get('/v/IndieGala-Helper.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('mozilla add-on'),
|
||||
value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?$/)
|
||||
name: 'mozilla add-on',
|
||||
value: isVPlusDottedVersionAtLeastOne
|
||||
}));
|
||||
|
||||
t.create('Version - Custom label')
|
||||
.get('/v/IndieGala-Helper.json?label=IndieGala Helper')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('IndieGala Helper'),
|
||||
value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?$/)
|
||||
name: 'IndieGala Helper',
|
||||
value: isVPlusDottedVersionAtLeastOne
|
||||
}));
|
||||
|
||||
t.create('Users')
|
||||
.get('/users/IndieGala-Helper.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('users'),
|
||||
name: 'users',
|
||||
value: Joi.string().regex(/^\d+$/)
|
||||
}));
|
||||
|
||||
t.create('Rating')
|
||||
.get('/rating/IndieGala-Helper.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('rating'),
|
||||
name: 'rating',
|
||||
value: Joi.string().regex(/^\d\/\d$/)
|
||||
}));
|
||||
|
||||
t.create('Stars')
|
||||
.get('/stars/IndieGala-Helper.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('rating'),
|
||||
value: Joi.string().regex(/^[\u2605\u2606]{5}$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'stars', value: isStarRating }));
|
||||
|
||||
t.create('Invalid addon')
|
||||
.get('/d/invalid-name-of-addon.json')
|
||||
@@ -2,30 +2,22 @@
|
||||
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
const { isMetric } = require('./helpers/validators');
|
||||
|
||||
const t = new ServiceTester({ id: 'ansible', title: 'Ansible Galaxy' });
|
||||
module.exports = t;
|
||||
|
||||
t.create('ansible role name')
|
||||
.get('/role/14542.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('role'),
|
||||
value: Joi.equal('openwisp.openwisp2')
|
||||
}));
|
||||
.expectJSON({ name: 'role', value: 'openwisp.openwisp2' });
|
||||
|
||||
t.create('ansible role download counts')
|
||||
.get('/role/d/14542.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('role downloads'),
|
||||
value: Joi.string().regex(/^[0-9]+[kMG]?$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'role downloads', value: isMetric }));
|
||||
|
||||
t.create('unkown role')
|
||||
.get('/role/000.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('role'),
|
||||
value: Joi.equal('not found')
|
||||
}));
|
||||
.expectJSON({ name: 'role', value: 'not found' });
|
||||
|
||||
t.create('connection error')
|
||||
.get('/role/14542.json')
|
||||
|
||||
@@ -3,54 +3,39 @@
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
|
||||
const isAppveyorBuildState = Joi.equal('failing', 'passing', 'running', 'queued');
|
||||
const isAppveyorTestTotals =
|
||||
Joi.string().regex(/^(?:[0-9]+ (?:passed|skipped|failed)(?:, )?)+$/);
|
||||
|
||||
const t = new ServiceTester({ id: 'appveyor', title: 'AppVeyor' });
|
||||
module.exports = t;
|
||||
|
||||
// Test AppVeyor build status badge
|
||||
t.create('CI build status')
|
||||
.get('/ci/gruntjs/grunt.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('build'),
|
||||
value: Joi.equal('failing', 'passing', 'running', 'queued')
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'build', value: isAppveyorBuildState }));
|
||||
|
||||
// Test AppVeyor branch build status badge
|
||||
t.create('CI build status on master branch')
|
||||
.get('/ci/gruntjs/grunt/master.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('build'),
|
||||
value: Joi.equal('failing', 'passing', 'running', 'queued')
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'build', value: isAppveyorBuildState }));
|
||||
|
||||
// Test AppVeyor build status badge on a non-existing project
|
||||
t.create('CI 404')
|
||||
.get('/ci/somerandomproject/thatdoesntexits.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('build'),
|
||||
value: Joi.string().regex(/^project not found or access denied$/),
|
||||
}));
|
||||
.expectJSON({ name: 'build', value: 'project not found or access denied' });
|
||||
|
||||
// Test AppVeyor tests status badge
|
||||
t.create('tests status')
|
||||
.get('/tests/NZSmartie/coap-net-iu0to.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('tests'),
|
||||
value: Joi.string().regex(/^(?:[0-9]+ (?:passed|skipped|failed)(?:, )?)+$/),
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'tests', value: isAppveyorTestTotals }));
|
||||
|
||||
// Test AppVeyor branch tests status badge
|
||||
t.create('tests status on master branch')
|
||||
.get('/tests/NZSmartie/coap-net-iu0to/master.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('tests'),
|
||||
value: Joi.string().regex(/^(?:[0-9]+ (?:passed|skipped|failed)(?:, )?)+$/),
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'tests', value: isAppveyorTestTotals }));
|
||||
|
||||
// Test AppVeyor tests status badge for a non-existing project
|
||||
t.create('tests 404')
|
||||
.get('/tests/somerandomproject/thatdoesntexits.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('tests'),
|
||||
value: Joi.string().regex(/^project not found or access denied$/),
|
||||
}));
|
||||
|
||||
.get('/tests/somerandomproject/thatdoesntexits.json')
|
||||
.expectJSON({ name: 'tests', value: 'project not found or access denied' });
|
||||
|
||||
@@ -2,73 +2,61 @@
|
||||
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
const { isVPlusDottedVersionAtLeastOne } = require('./helpers/validators');
|
||||
|
||||
const isBowerPrereleaseVersion = Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?(\-?\w)+?$/);
|
||||
|
||||
const t = new ServiceTester({ id: 'bower', title: 'Bower' });
|
||||
module.exports = t;
|
||||
|
||||
t.create('licence. eg. bower|MIT')
|
||||
.get('/l/bootstrap.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('bower'),
|
||||
value: Joi.equal('MIT')
|
||||
}));
|
||||
.get('/l/bootstrap.json')
|
||||
.expectJSON({ name: 'bower', value: 'MIT' });
|
||||
|
||||
t.create('custom label for licence. eg. my licence|MIT')
|
||||
.get('/l/bootstrap.json?label="my licence"')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('my licence'),
|
||||
value: Joi.equal('MIT')
|
||||
}));
|
||||
.get('/l/bootstrap.json?label="my licence"')
|
||||
.expectJSON({ name: 'my licence', value: 'MIT' });
|
||||
|
||||
t.create('version. eg. bower|v0.2.5')
|
||||
.get('/v/bootstrap.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('bower'),
|
||||
value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?$/)
|
||||
}));
|
||||
.get('/v/bootstrap.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: 'bower',
|
||||
value: isVPlusDottedVersionAtLeastOne
|
||||
}));
|
||||
|
||||
t.create('custom label for version. eg. my verison|v0.2.5')
|
||||
.get('/v/bootstrap.json?label="my verison"')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('my verison'),
|
||||
value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?$/)
|
||||
}));
|
||||
.get('/v/bootstrap.json?label="my version"')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: 'my version',
|
||||
value: isVPlusDottedVersionAtLeastOne
|
||||
}));
|
||||
|
||||
t.create('pre version. eg. bower|v0.2.5-alpha-rc-pre')
|
||||
.get('/vpre/bootstrap.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('bower'),
|
||||
value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?(-?\w)+?$/)
|
||||
}));
|
||||
.get('/vpre/bootstrap.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: 'bower',
|
||||
value: isBowerPrereleaseVersion
|
||||
}));
|
||||
|
||||
t.create('custom label for pre version. eg. pre verison|v0.2.5-alpha-rc-pre')
|
||||
.get('/vpre/bootstrap.json?label="pre verison"')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('pre verison'),
|
||||
value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?(-?\w)+?$/)
|
||||
}));
|
||||
.get('/vpre/bootstrap.json?label="pre verison"')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: 'pre verison',
|
||||
value: isBowerPrereleaseVersion
|
||||
}));
|
||||
|
||||
|
||||
t.create('Version for Invaild Package. eg. bower|invalid')
|
||||
.get('/v/it-is-a-invalid-package-should-error.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('bower'),
|
||||
value: Joi.equal('invalid')
|
||||
}));
|
||||
.get('/v/it-is-a-invalid-package-should-error.json')
|
||||
.expectJSON({ name: 'bower', value: 'invalid' });
|
||||
|
||||
t.create('Pre Version for Invaild Package. eg. bower|invalid')
|
||||
.get('/vpre/it-is-a-invalid-package-should-error.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('bower'),
|
||||
value: Joi.equal('invalid')
|
||||
}));
|
||||
.get('/vpre/it-is-a-invalid-package-should-error.json')
|
||||
.expectJSON({ name: 'bower', value: 'invalid' });
|
||||
|
||||
t.create('licence for Invaild Package. eg. bower|invalid')
|
||||
.get('/l/it-is-a-invalid-package-should-error.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('bower'),
|
||||
value: Joi.equal('invalid')
|
||||
}));
|
||||
.get('/l/it-is-a-invalid-package-should-error.json')
|
||||
.expectJSON({ name: 'bower', value: 'invalid' });
|
||||
|
||||
|
||||
t.create('Version label should be `no releases` if no offical version. eg. bower|no releases')
|
||||
@@ -76,7 +64,4 @@ t.create('Version label should be `no releases` if no offical version. eg. bower
|
||||
.intercept(nock => nock('https://libraries.io')
|
||||
.get('/api/bower/bootstrap')
|
||||
.reply(200, { latest_stable_release: { name: null } })) //or just `{}`
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('bower'),
|
||||
value: Joi.equal('no releases')
|
||||
}));
|
||||
.expectJSON({ name: 'bower', value: 'no releases' });
|
||||
|
||||
@@ -3,50 +3,47 @@
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
|
||||
const {
|
||||
isVPlusDottedVersionAtLeastOne,
|
||||
isStarRating,
|
||||
isMetric
|
||||
} = require('./helpers/validators');
|
||||
|
||||
const t = new ServiceTester({ id: 'chrome-web-store', title: 'Chrome Web Store' });
|
||||
module.exports = t;
|
||||
|
||||
t.create('Downloads (now users)')
|
||||
.get('/d/alhjnofcnnpeaphgeakdhkebafjcpeae.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('users'),
|
||||
value: Joi.string().regex(/^\d+k?$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'users', value: isMetric }));
|
||||
|
||||
t.create('Users')
|
||||
.get('/users/alhjnofcnnpeaphgeakdhkebafjcpeae.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('users'),
|
||||
value: Joi.string().regex(/^\d+k?$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'users', value: isMetric }));
|
||||
|
||||
t.create('Version')
|
||||
.get('/v/alhjnofcnnpeaphgeakdhkebafjcpeae.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('chrome web store'),
|
||||
value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?$/)
|
||||
name: 'chrome web store',
|
||||
value: isVPlusDottedVersionAtLeastOne
|
||||
}));
|
||||
|
||||
t.create('Version - Custom label')
|
||||
.get('/v/alhjnofcnnpeaphgeakdhkebafjcpeae.json?label=IndieGala Helper')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('IndieGala Helper'),
|
||||
value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?$/)
|
||||
name: 'IndieGala Helper',
|
||||
value: isVPlusDottedVersionAtLeastOne
|
||||
}));
|
||||
|
||||
t.create('Rating')
|
||||
.get('/rating/alhjnofcnnpeaphgeakdhkebafjcpeae.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('rating'),
|
||||
name: 'rating',
|
||||
value: Joi.string().regex(/^\d\.?\d+?\/5$/)
|
||||
}));
|
||||
|
||||
t.create('Stars')
|
||||
.get('/stars/alhjnofcnnpeaphgeakdhkebafjcpeae.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('rating'),
|
||||
value: Joi.string().regex(/^[\u2605\u2606]{5}$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'rating', value: isStarRating }));
|
||||
|
||||
t.create('Invalid addon')
|
||||
.get('/d/invalid-name-of-addon.json')
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
const { isPercentage } = require('./helpers/validators');
|
||||
|
||||
const t = new ServiceTester({ id: 'codecov', title: 'Codecov.io' });
|
||||
module.exports = t;
|
||||
@@ -10,12 +11,12 @@ t.create('gets coverage status')
|
||||
.get('/c/github/codecov/example-python.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: 'coverage',
|
||||
value: Joi.string().regex(/^[0-9]+%$/),
|
||||
value: isPercentage
|
||||
}));
|
||||
|
||||
t.create('gets coverate status for branch')
|
||||
.get('/c/github/codecov/example-python/master.json')
|
||||
.expectJSONTypes({
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: 'coverage',
|
||||
value: Joi.string().regex(/^[0-9]+%$/),
|
||||
});
|
||||
value: isPercentage
|
||||
}));
|
||||
|
||||
@@ -16,7 +16,7 @@ module.exports = t;
|
||||
t.create('Codetally')
|
||||
.get('/triggerman722/colorstrap.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('codetally'),
|
||||
name: 'codetally',
|
||||
value: Joi.string().regex(/\b\d+(?:.\d+)?/)
|
||||
}));
|
||||
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
const {
|
||||
isVPlusTripleDottedVersion,
|
||||
isMetric
|
||||
} = require('./helpers/validators');
|
||||
|
||||
const isCondaPlatform = Joi.string().regex(/^\w+-\d+( \| \w+-\d+)*$/);
|
||||
|
||||
const t = new ServiceTester({id: 'conda', title: 'Conda'});
|
||||
module.exports = t;
|
||||
@@ -9,86 +15,71 @@ module.exports = t;
|
||||
t.create('version')
|
||||
.get('/v/conda-forge/zlib.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('conda|conda-forge'),
|
||||
value: Joi.string().regex(/^v\d+\.\d+\.\d+$/)
|
||||
name: 'conda|conda-forge',
|
||||
value: isVPlusTripleDottedVersion
|
||||
}));
|
||||
|
||||
t.create('version (relabel)')
|
||||
.get('/v/conda-forge/zlib.json?label=123')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('123'),
|
||||
value: Joi.string().regex(/^v\d+\.\d+\.\d+$/)
|
||||
name: '123',
|
||||
value: isVPlusTripleDottedVersion
|
||||
}));
|
||||
|
||||
t.create('version (skip prefix)')
|
||||
.get('/vn/conda-forge/zlib.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('conda-forge'),
|
||||
value: Joi.string().regex(/^v\d+\.\d+\.\d+$/)
|
||||
name: 'conda-forge',
|
||||
value: isVPlusTripleDottedVersion
|
||||
}));
|
||||
|
||||
t.create('version (skip prefix, relabel)')
|
||||
.get('/vn/conda-forge/zlib.json?label=123')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('123'),
|
||||
value: Joi.string().regex(/^v\d+\.\d+\.\d+$/)
|
||||
name: '123',
|
||||
value: isVPlusTripleDottedVersion
|
||||
}));
|
||||
|
||||
t.create('platform')
|
||||
.get('/p/conda-forge/zlib.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('conda|platform'),
|
||||
value: Joi.string().regex(/^\w+-\d+( \| \w+-\d+)*$/)
|
||||
name: 'conda|platform',
|
||||
value: isCondaPlatform
|
||||
}));
|
||||
|
||||
t.create('platform (skip prefix)')
|
||||
.get('/pn/conda-forge/zlib.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('platform'),
|
||||
value: Joi.string().regex(/^\w+-\d+( \| \w+-\d+)*$/)
|
||||
name: 'platform',
|
||||
value: isCondaPlatform
|
||||
}));
|
||||
|
||||
t.create('platform (skip prefix,relabel)')
|
||||
.get('/pn/conda-forge/zlib.json?label=123')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('123'),
|
||||
value: Joi.string().regex(/^\w+-\d+( \| \w+-\d+)*$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: '123', value: isCondaPlatform }));
|
||||
|
||||
t.create('downloads')
|
||||
.get('/d/conda-forge/zlib.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('conda|downloads'),
|
||||
value: Joi.string().regex(/^[0-9]+[kMG]?$/)
|
||||
name: 'conda|downloads',
|
||||
value: isMetric
|
||||
}));
|
||||
|
||||
t.create('downloads (skip prefix)')
|
||||
.get('/dn/conda-forge/zlib.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
value: Joi.string().regex(/^[0-9]+[kMG]?$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'downloads', value: isMetric }));
|
||||
|
||||
t.create('downloads (skip prefix, relabel)')
|
||||
.get('/dn/conda-forge/zlib.json?label=123')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('123'),
|
||||
value: Joi.string().regex(/^[0-9]+[kMG]?$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: '123', value: isMetric }));
|
||||
|
||||
t.create('unknown package')
|
||||
.get('/d/conda-forge/some-bogus-package-that-never-exists.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('conda|downloads'),
|
||||
value: Joi.equal('invalid')
|
||||
}));
|
||||
.expectJSON({ name: 'conda|downloads', value: 'invalid' });
|
||||
|
||||
t.create('unknown channel')
|
||||
.get('/d/some-bogus-channel-that-never-exists/zlib.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('conda|downloads'),
|
||||
value: Joi.equal('invalid')
|
||||
}));
|
||||
.expectJSON({ name: 'conda|downloads', value: 'invalid' });
|
||||
|
||||
t.create('unknown info')
|
||||
.get('/x/conda-forge/zlib.json')
|
||||
|
||||
@@ -9,14 +9,14 @@ module.exports = t;
|
||||
t.create('build status on default branch')
|
||||
.get('/git-hub/doctrine/dbal.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('build'),
|
||||
name: 'build',
|
||||
value: Joi.equal('failing', 'passing', 'unknown', 'unstable')
|
||||
}));
|
||||
|
||||
t.create('build status on named branch')
|
||||
.get('/git-hub/doctrine/dbal/develop.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('build'),
|
||||
name: 'build',
|
||||
value: Joi.equal('failing', 'passing', 'unknown')
|
||||
}));
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
const { isVPlusTripleDottedVersion } = require('./helpers/validators');
|
||||
|
||||
const t = new ServiceTester({ id: 'cran', title: 'CRAN/METACRAN' });
|
||||
module.exports = t;
|
||||
@@ -9,8 +10,8 @@ module.exports = t;
|
||||
t.create('version')
|
||||
.get('/v/devtools.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('cran'),
|
||||
value: Joi.string().regex(/^v\d+\.\d+\.\d+$/)
|
||||
name: 'cran',
|
||||
value: isVPlusTripleDottedVersion
|
||||
}));
|
||||
|
||||
t.create('specified license')
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
|
||||
const t = new ServiceTester({ id: 'crates', title: 'crates.io' });
|
||||
@@ -8,14 +7,8 @@ module.exports = t;
|
||||
|
||||
t.create('license')
|
||||
.get('/l/libc.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('license'),
|
||||
value: Joi.equal('MIT/Apache-2.0')
|
||||
}));
|
||||
.expectJSON({ name: 'license', value: 'MIT/Apache-2.0' });
|
||||
|
||||
t.create('license (with version)')
|
||||
.get('/l/libc/0.2.31.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('license'),
|
||||
value: Joi.equal('MIT/Apache-2.0')
|
||||
}));
|
||||
.expectJSON({ name: 'license', value: 'MIT/Apache-2.0' });
|
||||
|
||||
@@ -9,7 +9,7 @@ module.exports = t;
|
||||
t.create('gets status for Reactiflux')
|
||||
.get('/102860784329052160.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('chat'),
|
||||
name: 'chat',
|
||||
value: Joi.string().regex(/^[0-9]+ online$/),
|
||||
}));
|
||||
|
||||
|
||||
@@ -2,55 +2,53 @@
|
||||
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
const {
|
||||
isMetric,
|
||||
isFileSize,
|
||||
isFormattedDate,
|
||||
isVPlusDottedVersionAtLeastOne
|
||||
} = require('./helpers/validators');
|
||||
|
||||
const t = new ServiceTester({ id: 'github', title: 'Github' });
|
||||
module.exports = t;
|
||||
|
||||
const validDateString = Joi.alternatives().try(
|
||||
Joi.equal('today', 'yesterday'),
|
||||
Joi.string().regex(/^last (sun|mon|tues|wednes|thurs|fri|satur)day$/),
|
||||
Joi.string().regex(/^(january|february|march|april|may|june|july|august|september|october|november|december)( \d{4})?$/));
|
||||
|
||||
t.create('License')
|
||||
.get('/license/badges/shields.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('license'),
|
||||
value: Joi.string()
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'license', value: Joi.string() }));
|
||||
|
||||
t.create('Contributors')
|
||||
.get('/contributors/cdnjs/cdnjs.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('contributors'),
|
||||
name: 'contributors',
|
||||
value: Joi.string().regex(/^\w+$/)
|
||||
}));
|
||||
|
||||
t.create('GitHub closed pull requests')
|
||||
.get('/issues-pr-closed/badges/shields.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('pull requests'),
|
||||
name: 'pull requests',
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]? closed$/)
|
||||
}));
|
||||
|
||||
t.create('GitHub closed pull requests raw')
|
||||
.get('/issues-pr-closed-raw/badges/shields.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('closed pull requests'),
|
||||
name: 'closed pull requests',
|
||||
value: Joi.string().regex(/^\w+?$/)
|
||||
}));
|
||||
|
||||
t.create('GitHub pull requests')
|
||||
.get('/issues-pr/badges/shields.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('pull requests'),
|
||||
name: 'pull requests',
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]? open$/)
|
||||
}));
|
||||
|
||||
t.create('GitHub pull requests raw')
|
||||
.get('/issues-pr-raw/badges/shields.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('open pull requests'),
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]?$/)
|
||||
name: 'open pull requests',
|
||||
value: isMetric
|
||||
}));
|
||||
|
||||
t.create('GitHub closed issues')
|
||||
@@ -76,10 +74,7 @@ t.create('GitHub open issues')
|
||||
|
||||
t.create('GitHub open issues raw')
|
||||
.get('/issues-raw/badges/shields.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('open issues'),
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]?$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'open issues', value: isMetric }));
|
||||
|
||||
t.create('GitHub open issues by label')
|
||||
.get('/issues/badges/shields/vendor-badge.json')
|
||||
@@ -92,7 +87,7 @@ t.create('GitHub open issues by label (raw)')
|
||||
.get('/issues-raw/badges/shields/vendor-badge.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('open vendor-badge issues'),
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]?$/)
|
||||
value: isMetric
|
||||
}));
|
||||
|
||||
t.create('GitHub open pull requests by label')
|
||||
@@ -105,35 +100,35 @@ t.create('GitHub open pull requests by label')
|
||||
t.create('GitHub open pull requests by label (raw)')
|
||||
.get('/issues-pr-raw/badges/shields/vendor-badge.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('open vendor-badge pull requests'),
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]?$/)
|
||||
name: 'open vendor-badge pull requests',
|
||||
value: isMetric
|
||||
}));
|
||||
|
||||
t.create('Followers')
|
||||
.get('/followers/webcaetano.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('followers'),
|
||||
name: 'followers',
|
||||
value: Joi.string().regex(/^\w+$/)
|
||||
}));
|
||||
|
||||
t.create('Watchers')
|
||||
.get('/watchers/badges/shields.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('watchers'),
|
||||
name: 'watchers',
|
||||
value: Joi.number().integer().positive()
|
||||
}));
|
||||
|
||||
t.create('Stars')
|
||||
.get('/stars/badges/shields.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('stars'),
|
||||
name: 'stars',
|
||||
value: Joi.string().regex(/^\w+$/)
|
||||
}));
|
||||
|
||||
t.create('Forks')
|
||||
.get('/forks/badges/shields.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('forks'),
|
||||
name: 'forks',
|
||||
value: Joi.number().integer().positive()
|
||||
}));
|
||||
|
||||
@@ -153,30 +148,24 @@ t.create('Commits since by latest release')
|
||||
|
||||
t.create('Release')
|
||||
.get('/release/photonstorm/phaser.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('release'),
|
||||
value: Joi.string()
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'release', value: Joi.string() }));
|
||||
|
||||
t.create('(pre-)Release')
|
||||
.get('/release/photonstorm/phaser/all.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('release'),
|
||||
value: Joi.string()
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'release', value: Joi.string() }));
|
||||
|
||||
t.create('Release Date. e.g release date|today')
|
||||
.get('/release-date/microsoft/vscode.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: 'release date',
|
||||
value: validDateString
|
||||
value: isFormattedDate
|
||||
}));
|
||||
|
||||
t.create('Release Date - Custom Label. e.g myRelease|today')
|
||||
.get('/release-date/microsoft/vscode.json?label=myRelease')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: 'myRelease',
|
||||
value: validDateString
|
||||
value: isFormattedDate
|
||||
}));
|
||||
|
||||
t.create('Release Date - Should return `no releases or repo not found` for invalid repo')
|
||||
@@ -187,14 +176,14 @@ t.create('(Pre-)Release Date. e.g release date|today')
|
||||
.get('/release-date-pre/microsoft/vscode.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: 'release date',
|
||||
value: validDateString
|
||||
value: isFormattedDate
|
||||
}));
|
||||
|
||||
t.create('(Pre-)Release Date - Custom Label. e.g myRelease|today')
|
||||
.get('/release-date-pre/microsoft/vscode.json?label=myRelease')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: 'myRelease',
|
||||
value: validDateString
|
||||
value: isFormattedDate
|
||||
}));
|
||||
|
||||
t.create('(Pre-)Release Date - Should return `no releases or repo not found` for invalid repo')
|
||||
@@ -204,31 +193,22 @@ t.create('(Pre-)Release Date - Should return `no releases or repo not found` for
|
||||
|
||||
t.create('Tag')
|
||||
.get('/tag/photonstorm/phaser.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('tag'),
|
||||
value: Joi.string()
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'tag', value: Joi.string() }));
|
||||
|
||||
t.create('Package version')
|
||||
.get('/package-json/v/badges/shields.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('package'),
|
||||
value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?$/)
|
||||
name: 'package',
|
||||
value: isVPlusDottedVersionAtLeastOne
|
||||
}));
|
||||
|
||||
t.create('Package name')
|
||||
.get('/package-json/n/badges/shields.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('package name'),
|
||||
value: Joi.equal('gh-badges')
|
||||
}));
|
||||
.expectJSON({ name: 'package name', value: 'gh-badges' });
|
||||
|
||||
t.create('Package name - Custom label')
|
||||
.get('/package-json/name/badges/shields.json?label=Dev Name')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('Dev Name'),
|
||||
value: Joi.equal('gh-badges')
|
||||
}));
|
||||
.expectJSON({ name: 'Dev Name', value: 'gh-badges' });
|
||||
|
||||
t.create('Package array')
|
||||
.get('/package-json/keywords/badges/shields.json')
|
||||
@@ -239,107 +219,83 @@ t.create('Package array')
|
||||
|
||||
t.create('Package object')
|
||||
.get('/package-json/dependencies/badges/shields.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('package dependencies'),
|
||||
value: Joi.equal('invalid data')
|
||||
}));
|
||||
.expectJSON({ name: 'package dependencies', value: 'invalid data' });
|
||||
|
||||
t.create('Manifest version')
|
||||
.get('/manifest-json/v/RedSparr0w/IndieGala-Helper.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('manifest'),
|
||||
value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?$/)
|
||||
name: 'manifest',
|
||||
value: isVPlusDottedVersionAtLeastOne
|
||||
}));
|
||||
|
||||
t.create('Manifest name')
|
||||
.get('/manifest-json/n/RedSparr0w/IndieGala-Helper.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('manifest name'),
|
||||
value: Joi.equal('IndieGala Helper')
|
||||
}));
|
||||
.expectJSON({ name: 'manifest name', value: 'IndieGala Helper' });
|
||||
|
||||
t.create('Manifest array')
|
||||
.get('/manifest-json/permissions/RedSparr0w/IndieGala-Helper.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('manifest permissions'),
|
||||
name: 'manifest permissions',
|
||||
value: Joi.string().regex(/.*?,/)
|
||||
}));
|
||||
|
||||
t.create('Manifest object')
|
||||
.get('/manifest-json/background/RedSparr0w/IndieGala-Helper.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('manifest background'),
|
||||
value: Joi.equal('invalid data')
|
||||
}));
|
||||
.expectJSON({ name: 'manifest background', value: 'invalid data' });
|
||||
|
||||
t.create('Manifest invalid json response')
|
||||
.get('/manifest-json/v/RedSparr0w/not-a-real-project.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('manifest'),
|
||||
value: Joi.equal('invalid data')
|
||||
}));
|
||||
.expectJSON({ name: 'manifest', value: 'invalid data' });
|
||||
|
||||
t.create('Manifest no network connection')
|
||||
.get('/manifest-json/v/RedSparr0w/IndieGala-Helper.json')
|
||||
.networkOff()
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('manifest'),
|
||||
value: Joi.equal('inaccessible')
|
||||
}));
|
||||
.expectJSON({ name: 'manifest', value: 'inaccessible' });
|
||||
|
||||
t.create('File size')
|
||||
.get('/size/webcaetano/craft/build/phaser-craft.min.js.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('size'),
|
||||
value: Joi.string().regex(/^[0-9]*[.]?[0-9]+\s(B|kB|MB|GB|TB|PB|EB|ZB|YB)$/),
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'size', value: isFileSize }));
|
||||
|
||||
t.create('File size 404')
|
||||
.get('/size/webcaetano/craft/build/does-not-exist.min.js.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('size'),
|
||||
value: Joi.string().regex(/^repo or file not found$/),
|
||||
}));
|
||||
.expectJSON({ name: 'size', value: 'repo or file not found' });
|
||||
|
||||
t.create('File size for "not a regular file"')
|
||||
.get('/size/webcaetano/craft/build.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('size'),
|
||||
value: Joi.string().regex(/^not a regular file$/),
|
||||
}));
|
||||
.expectJSON({ name: 'size', value: 'not a regular file' });
|
||||
|
||||
t.create('Downloads all releases')
|
||||
.get('/downloads/photonstorm/phaser/total.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
name: 'downloads',
|
||||
value: Joi.string().regex(/^\w+\s+total$/)
|
||||
}));
|
||||
|
||||
t.create('downloads for release without slash')
|
||||
.get('/downloads/atom/atom/v0.190.0/total.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
name: 'downloads',
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]? v0\.190\.0$/)
|
||||
}));
|
||||
|
||||
t.create('downloads for specific asset without slash')
|
||||
.get('/downloads/atom/atom/v0.190.0/atom-amd64.deb.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
name: 'downloads',
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]? v0\.190\.0 \[atom-amd64\.deb\]$/)
|
||||
}));
|
||||
|
||||
t.create('downloads for release with slash')
|
||||
.get('/downloads/NHellFire/dban/stable/v2.2.8/total.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
name: 'downloads',
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]? stable\/v2\.2\.8$/)
|
||||
}));
|
||||
|
||||
t.create('downloads for specific asset with slash')
|
||||
.get('/downloads/NHellFire/dban/stable/v2.2.8/dban-2.2.8_i586.iso.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
name: 'downloads',
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]? stable\/v2\.2\.8 \[dban-2\.2\.8_i586\.iso\]$/)
|
||||
}));
|
||||
|
||||
@@ -349,17 +305,11 @@ t.create('downloads for unknown release')
|
||||
|
||||
t.create('hit counter')
|
||||
.get('/search/torvalds/linux/goto.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('goto counter'),
|
||||
value: Joi.string().regex(/^[0-9]*(k|M|G|T|P|E|Z|Y)$/),
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'goto counter', value: isMetric }));
|
||||
|
||||
t.create('hit counter for nonexistent repo')
|
||||
.get('/search/torvalds/not-linux/goto.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('goto counter'),
|
||||
value: Joi.string().regex(/^repo not found$/),
|
||||
}));
|
||||
.expectJSON({ name: 'goto counter', value: 'repo not found' });
|
||||
|
||||
t.create('commit activity (1 year)')
|
||||
.get('/commit-activity/y/eslint/eslint.json')
|
||||
@@ -384,21 +334,15 @@ t.create('commit activity (1 week)')
|
||||
|
||||
t.create('last commit (recent)')
|
||||
.get('/last-commit/eslint/eslint.json')
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'last commit', value: validDateString }));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'last commit', value: isFormattedDate }));
|
||||
|
||||
t.create('last commit (ancient)')
|
||||
.get('/last-commit/badges/badgr.co.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('last commit'),
|
||||
value: Joi.equal('january 2014'),
|
||||
}));
|
||||
.expectJSON({ name: 'last commit', value: 'january 2014' });
|
||||
|
||||
t.create('last commit (on branch)')
|
||||
.get('/last-commit/badges/badgr.co/shielded.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('last commit'),
|
||||
value: Joi.equal('july 2013'),
|
||||
}));
|
||||
.expectJSON({ name: 'last commit', value: 'july 2013' });
|
||||
|
||||
t.create('github issue state')
|
||||
.get('/issues/detail/s/badges/shields/979.json')
|
||||
@@ -434,11 +378,11 @@ t.create('github issue comments')
|
||||
|
||||
t.create('github issue age')
|
||||
.get('/issues/detail/age/badges/shields/979.json')
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'created', value: validDateString }));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'created', value: isFormattedDate }));
|
||||
|
||||
t.create('github issue update')
|
||||
.get('/issues/detail/last-update/badges/shields/979.json')
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'updated', value: validDateString }));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'updated', value: isFormattedDate }));
|
||||
|
||||
t.create('github pull request check state')
|
||||
.get('/status/s/pulls/badges/shields/1110.json')
|
||||
|
||||
33
service-tests/helpers/validators.js
Normal file
33
service-tests/helpers/validators.js
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
const Joi = require('joi');
|
||||
|
||||
const withRegex = (re) => Joi.string().regex(re);
|
||||
|
||||
const isVPlusTripleDottedVersion = withRegex(/^v[0-9]+.[0-9]+.[0-9]+$/);
|
||||
|
||||
const isVPlusDottedVersionAtLeastOne = withRegex(/^v\d+(\.\d+)?(\.\d+)?$/);
|
||||
|
||||
const isStarRating = withRegex(/^[\u2605\u2606]{5}$/);
|
||||
|
||||
const isMetric = withRegex(/^[0-9]+[kMGTPEZY]?$/);
|
||||
|
||||
const isPercentage = withRegex(/^[0-9]+\%$/);
|
||||
|
||||
const isFileSize = withRegex(/^[0-9]*[.]?[0-9]+\s(B|kB|MB|GB|TB|PB|EB|ZB|YB)$/);
|
||||
|
||||
const isFormattedDate = Joi.alternatives().try(
|
||||
Joi.equal('today', 'yesterday'),
|
||||
Joi.string().regex(/^last (sun|mon|tues|wednes|thurs|fri|satur)day$/),
|
||||
Joi.string().regex(/^(january|february|march|april|may|june|july|august|september|october|november|december)( \d{4})?$/));
|
||||
|
||||
|
||||
module.exports = {
|
||||
isVPlusTripleDottedVersion,
|
||||
isVPlusDottedVersionAtLeastOne,
|
||||
isStarRating,
|
||||
isMetric,
|
||||
isPercentage,
|
||||
isFileSize,
|
||||
isFormattedDate
|
||||
};
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
const { isMetric } = require('./helpers/validators');
|
||||
|
||||
const isHexpmVersion = Joi.string().regex(/^v\d+.\d+.?\d?$/);
|
||||
|
||||
const t = new ServiceTester({ id: 'hexpm', title: 'Hex.pm' });
|
||||
module.exports = t;
|
||||
@@ -9,35 +12,29 @@ module.exports = t;
|
||||
t.create('downloads per week')
|
||||
.get('/dw/cowboy.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
name: 'downloads',
|
||||
value: Joi.string().regex(/^\d+[a-z]?\/week$/)
|
||||
}));
|
||||
|
||||
t.create('downloads per day')
|
||||
.get('/dd/cowboy.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
name: 'downloads',
|
||||
value: Joi.string().regex(/^\d+[a-z]?\/day$/)
|
||||
}));
|
||||
|
||||
t.create('downloads in total')
|
||||
.get('/dt/cowboy.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
value: Joi.string().regex(/^\d+[kMGTPEZY]?$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'downloads', value: isMetric }));
|
||||
|
||||
t.create('version')
|
||||
.get('/v/cowboy.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('hex'),
|
||||
value: Joi.string().regex(/^v\d+.\d+.?\d?$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'hex', value: isHexpmVersion }));
|
||||
|
||||
t.create('license')
|
||||
.get('/l/cowboy.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('license'),
|
||||
name: 'license',
|
||||
value: Joi.string().required()
|
||||
}));
|
||||
|
||||
|
||||
@@ -2,30 +2,22 @@
|
||||
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
const { isMetric } = require('./helpers/validators');
|
||||
|
||||
const t = new ServiceTester({ id: 'jetbrains', title: 'JetBrains plugin' });
|
||||
module.exports = t;
|
||||
|
||||
t.create('downloads (number as a plugin id)')
|
||||
.get('/plugin/d/7495.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'downloads', value: isMetric }));
|
||||
|
||||
t.create('downloads (plugin id from plugin.xml)')
|
||||
.get('/plugin/d/org.intellij.scala.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'downloads', value: isMetric }));
|
||||
|
||||
t.create('downloads (user friendly plugin id)')
|
||||
.get('/plugin/d/1347-scala.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'downloads', value: isMetric }));
|
||||
|
||||
t.create('unknown plugin')
|
||||
.get('/plugin/d/unknown-plugin.json')
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
|
||||
// Github allows versions with chars, etc.
|
||||
const isAnyV = Joi.string().regex(/^v.+$/);
|
||||
|
||||
const t = new ServiceTester({ id: 'jitpack', title: 'JitPack' });
|
||||
module.exports = t;
|
||||
|
||||
t.create('version')
|
||||
.get('/v/jitpack/maven-simple.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('JitPack'),
|
||||
value: Joi.string().regex(/^v.+$/)//Github allows versions with chars, etc.
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'JitPack', value: isAnyV }));
|
||||
|
||||
t.create('unknown package')
|
||||
.get('/v/some-bogus-user/project.json')
|
||||
|
||||
@@ -6,11 +6,13 @@ const ServiceTester = require('./runner/service-tester');
|
||||
const t = new ServiceTester({ id: 'luarocks', title: 'LuaRocks' });
|
||||
module.exports = t;
|
||||
|
||||
const isLuaVersion = Joi.string().regex(/^v\d+\.\d+\.\d+-\d+$/);
|
||||
|
||||
t.create('version')
|
||||
.get('/v/mpeterv/luacheck.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('luarocks'),
|
||||
value: Joi.string().regex(/^v\d+\.\d+\.\d+-\d+$/)
|
||||
name: 'luarocks',
|
||||
value: isLuaVersion
|
||||
}));
|
||||
|
||||
t.create('unknown package')
|
||||
|
||||
@@ -9,14 +9,14 @@ module.exports = t;
|
||||
t.create('latest version')
|
||||
.get('/v/com.github.fabriziocucci/yacl4j.json') // http://repo1.maven.org/maven2/com/github/fabriziocucci/yacl4j/
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('maven-central'),
|
||||
name: 'maven-central',
|
||||
value: Joi.string().regex(/^v(.*)$/)
|
||||
}));
|
||||
|
||||
t.create('latest 0.8 version')
|
||||
.get('/v/com.github.fabriziocucci/yacl4j/0.8.json') // http://repo1.maven.org/maven2/com/github/fabriziocucci/yacl4j/
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('maven-central'),
|
||||
name: 'maven-central',
|
||||
value: Joi.string().regex(/^v0\.8(.*)$/)
|
||||
}));
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ module.exports = t;
|
||||
t.create('search release version')
|
||||
.get('/r/https/repository.jboss.org/nexus/jboss/jboss-client.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('nexus'),
|
||||
name: 'nexus',
|
||||
value: Joi.string().regex(/^4(\.\d+)+$/)
|
||||
}));
|
||||
|
||||
@@ -20,7 +20,7 @@ t.create('search release version of an inexistent artifact')
|
||||
t.create('search snapshot version')
|
||||
.get('/s/https/repository.jboss.org/nexus/com.progress.fuse/fusehq.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('nexus'),
|
||||
name: 'nexus',
|
||||
value: Joi.string().regex(/-SNAPSHOT$/)
|
||||
}));
|
||||
|
||||
@@ -43,14 +43,14 @@ t.create('search snapshot version of an inexistent artifact')
|
||||
t.create('resolve version')
|
||||
.get('/developer/https/repository.jboss.org/nexus/ai.h2o/h2o-automl.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('nexus'),
|
||||
name: 'nexus',
|
||||
value: Joi.string().regex(/^3(\.\d+)+$/)
|
||||
}));
|
||||
|
||||
t.create('resolve version with query')
|
||||
.get('/fs-public-snapshots/https/repository.jboss.org/nexus/com.progress.fuse/fusehq:c=agent-apple-osx:p=tar.gz.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('nexus'),
|
||||
name: 'nexus',
|
||||
value: Joi.string().regex(/^7(\.\d+)+-SNAPSHOT$/)
|
||||
}));
|
||||
|
||||
|
||||
@@ -2,48 +2,45 @@
|
||||
|
||||
const Joi = require('joi');
|
||||
const ServiceTester = require('./runner/service-tester');
|
||||
const {
|
||||
isVPlusTripleDottedVersion,
|
||||
isMetric
|
||||
} = require('./helpers/validators');
|
||||
|
||||
const isVscodeRating = Joi.string().regex(/[0-5].[0-9]{2}\/5?\s*\([0-9]*\)$/);
|
||||
|
||||
const t = new ServiceTester({ id: 'vscode-marketplace', title: 'VS Code Marketplace' });
|
||||
module.exports = t;
|
||||
|
||||
t.create('downloads should be formatted. eg. downloads|72M')
|
||||
.get('/d/ritwickdey.LiveServer.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('downloads'),
|
||||
value: Joi.string().regex(/^[0-9]+[K|M]?$/i)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'downloads', value: isMetric }));
|
||||
|
||||
t.create('downloads label should be changed to custom label. eg. Total Installs|72M')
|
||||
.get('/d/ritwickdey.LiveServer.json?label="Total Installs"')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('Total Installs'),
|
||||
value: Joi.string().regex(/^[0-9]+[K|M]?$/i)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'Total Installs', value: isMetric }));
|
||||
|
||||
t.create('rating should be formatted. eg. rating|4.25/5(30)')
|
||||
.get('/r/ritwickdey.LiveServer.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('rating'),
|
||||
value: Joi.string().regex(/[0-5].[0-9]{2}\/5?\s*\([0-9]*\)$/)
|
||||
}));
|
||||
.expectJSONTypes(Joi.object().keys({ name: 'rating', value: isVscodeRating }));
|
||||
|
||||
t.create('rating label should be changed to custom label. eg. My custom rating label|4.25/5(30)')
|
||||
.get('/r/ritwickdey.LiveServer.json?label="My custom rating label"')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('My custom rating label'),
|
||||
value: Joi.string().regex(/[0-5].[0-9]{2}\/5?\s*\([0-9]*\)$/)
|
||||
name: 'My custom rating label',
|
||||
value: isVscodeRating
|
||||
}));
|
||||
|
||||
t.create('version should be formatted. eg. Visual Studio Marketplace|v7.2.5')
|
||||
.get('/v/ritwickdey.LiveServer.json')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('visual studio marketplace'),
|
||||
value: Joi.string().regex(/^v[0-9]*.[0-9]*.[0-9]*$/)
|
||||
name: 'visual studio marketplace',
|
||||
value: isVPlusTripleDottedVersion
|
||||
}));
|
||||
|
||||
t.create('version label should be changed to custom label. eg. VSM|v7.2.5')
|
||||
.get('/v/ritwickdey.LiveServer.json?label=VSM')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('VSM'),
|
||||
value: Joi.string().regex(/^v[0-9]*.[0-9]*.[0-9]*$/)
|
||||
name: 'VSM',
|
||||
value: isVPlusTripleDottedVersion
|
||||
}));
|
||||
|
||||
@@ -41,14 +41,11 @@ t.create('label should be `bug` & value should be exactly 5 as supplied in `fake
|
||||
.intercept(nock => nock('https://api.waffle.io/')
|
||||
.get('/userName/repoName/cards')
|
||||
.reply(200, fakeData))
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('bug'),
|
||||
value: Joi.equal('5')
|
||||
}));
|
||||
.expectJSON({ name: 'bug', value: '5' });
|
||||
|
||||
t.create('label should be `Mybug` & value should be formated. e.g: Mybug|25')
|
||||
.get('/label/ritwickdey/vscode-live-server/bug.json?label=Mybug')
|
||||
.expectJSONTypes(Joi.object().keys({
|
||||
name: Joi.equal('Mybug'),
|
||||
name: 'Mybug',
|
||||
value: Joi.string().regex(/^\d+$/)
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user