-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
203 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const Joi = require('joi'); | ||
|
||
// requires just `maxConcurrentReqs` | ||
const schema = Joi.object().keys({ | ||
imports: { | ||
adminLookup: { | ||
maxConcurrentReqs: Joi.number().integer() | ||
} | ||
} | ||
}).unknown(true); | ||
|
||
module.exports = { | ||
validate: function validate(config) { | ||
Joi.validate(config, schema, { allowUnknown: true }, (err, value) => { | ||
if (err) { | ||
throw new Error(err.details[0].message); | ||
} | ||
}); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
'use strict'; | ||
|
||
const tape = require('tape'); | ||
|
||
const configValidation = require('../src/configValidation'); | ||
const proxyquire = require('proxyquire').noCallThru(); | ||
|
||
tape('tests configuration scenarios', function(test) { | ||
test.test('missing imports should not throw error', function(t) { | ||
const config = {}; | ||
|
||
t.doesNotThrow(function() { | ||
configValidation.validate(config); | ||
}); | ||
t.end(); | ||
|
||
}); | ||
|
||
test.test('non-object imports should throw error', function(t) { | ||
[null, 17, 'string', [], true].forEach((value) => { | ||
const config = { imports: value }; | ||
|
||
t.throws(function() { | ||
configValidation.validate(config); | ||
}, /"imports" must be an object/); | ||
}); | ||
|
||
t.end(); | ||
|
||
}); | ||
|
||
test.test('missing imports.adminLookup should not throw error', function(t) { | ||
const config = { | ||
imports: { | ||
} | ||
}; | ||
|
||
t.doesNotThrow(function() { | ||
configValidation.validate(config); | ||
}); | ||
t.end(); | ||
|
||
}); | ||
|
||
test.test('non-object imports.adminLookup should throw error', function(t) { | ||
[null, 17, 'string', [], true].forEach((value) => { | ||
const config = { | ||
imports: { | ||
adminLookup: value | ||
} | ||
}; | ||
|
||
t.throws(function() { | ||
configValidation.validate(config); | ||
}, /"adminLookup" must be an object/); | ||
}); | ||
|
||
t.end(); | ||
|
||
}); | ||
|
||
test.test('non-number imports.adminLookup.maxConcurrentReqs should throw error', function(t) { | ||
[null, 'string', {}, [], true].forEach((value) => { | ||
const config = { | ||
imports: { | ||
adminLookup: { | ||
maxConcurrentReqs: value | ||
} | ||
} | ||
}; | ||
|
||
t.throws(function() { | ||
configValidation.validate(config); | ||
}, /"maxConcurrentReqs" must be a number/); | ||
|
||
}); | ||
|
||
t.end(); | ||
|
||
}); | ||
|
||
test.test('non-integer imports.adminLookup.maxConcurrentReqs should throw error', function(t) { | ||
const config = { | ||
imports: { | ||
adminLookup: { | ||
maxConcurrentReqs: 17.3 | ||
} | ||
} | ||
}; | ||
|
||
t.throws(function() { | ||
configValidation.validate(config); | ||
}, /"maxConcurrentReqs" must be an integer/); | ||
|
||
t.end(); | ||
|
||
}); | ||
|
||
test.test('missing imports.adminLookup.maxConcurrentReqs should not throw error', function(t) { | ||
const config = { | ||
imports: { | ||
adminLookup: { | ||
} | ||
} | ||
}; | ||
|
||
t.doesNotThrow(function() { | ||
configValidation.validate(config); | ||
}); | ||
|
||
t.end(); | ||
|
||
}); | ||
|
||
test.test('integer imports.adminLookup.maxConcurrentReqs should not throw error', function(t) { | ||
const config = { | ||
imports: { | ||
adminLookup: { | ||
maxConcurrentReqs: 17 | ||
} | ||
} | ||
}; | ||
|
||
t.doesNotThrow(function() { | ||
configValidation.validate(config); | ||
}); | ||
|
||
t.end(); | ||
|
||
}); | ||
|
||
test.test('unknown properties should not throw errors', function(t) { | ||
const config = { | ||
imports: { | ||
adminLookup: { | ||
maxConcurrentReqs: 17, | ||
unknown_property: 'property value' | ||
} | ||
} | ||
}; | ||
|
||
t.doesNotThrow(function() { | ||
configValidation.validate(config); | ||
}); | ||
|
||
t.end(); | ||
|
||
}); | ||
|
||
}); | ||
|
||
tape('tests for main entry point', function(test) { | ||
test.test('configValidation throwing error should rethrow', function(t) { | ||
const config = {}; | ||
|
||
t.throws(function() { | ||
proxyquire('../index', { | ||
'./src/configValidation': { | ||
validate: () => { | ||
throw Error('config is not valid'); | ||
} | ||
} | ||
}); | ||
|
||
configValidation.validate(config); | ||
}, /config is not valid/); | ||
t.end(); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require ('./configValidationTest.js'); | ||
require ('./lookupStreamTest.js'); | ||
require ('./resolversFactoryTest.js'); | ||
require ('./resolversFactoryLocalTest.js'); |