[librariesio] Missing try/catch block and tests (#1644)

This commit is contained in:
Pyves
2018-04-14 08:35:47 +01:00
committed by GitHub
parent e1755df212
commit ac13fdb8d4
3 changed files with 87 additions and 38 deletions

View File

@@ -0,0 +1,41 @@
'use strict';
const Joi = require('joi');
const ServiceTester = require('../service-tester');
const {
isDependencyState
} = require('../test-validators');
const t = new ServiceTester({ id: 'librariesio', title: 'Libraries.io' });
module.exports = t;
t.create('dependencies for releases')
.get('/release/hex/phoenix/1.0.3.json')
.expectJSONTypes(Joi.object().keys({
name: 'dependencies',
value: isDependencyState,
}));
t.create('dependencies for github')
.get('/github/pyvesb/notepad4e.json')
.expectJSONTypes(Joi.object().keys({
name: 'dependencies',
value: isDependencyState,
}));
t.create('release not found')
.get('/release/hex/invalid/4.0.4.json')
.expectJSON({
name: 'dependencies',
value: 'not available',
});
t.create('no response data')
.get('/github/phoenixframework/phoenix.json')
.intercept(nock => nock('https://libraries.io')
.get('/api/github/phoenixframework/phoenix/dependencies')
.reply(200))
.expectJSON({
name: 'dependencies',
value: 'invalid',
});

View File

@@ -67,6 +67,8 @@ const isFormattedDate = Joi.alternatives().try(
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})?$/));
const isDependencyState = withRegex(/^(\d+ out of date|\d+ deprecated|up to date)$/);
module.exports = {
isSemver,
isVPlusTripleDottedVersion,
@@ -83,5 +85,6 @@ module.exports = {
isIntegerPercentage,
isDecimalPercentage,
isFileSize,
isFormattedDate
isFormattedDate,
isDependencyState
};