-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Merge pull request #182 from pelias/add-joi-config-validation
added schema validation and updated lint configuration
- Loading branch information
Showing
8 changed files
with
167 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
{ | ||
"node": true, | ||
|
||
"curly": true, | ||
"latedef": true, | ||
"quotmark": true, | ||
"eqeqeq": true, | ||
"esversion": 6, | ||
"freeze": true, | ||
"immed": true, | ||
"indent": 2, | ||
"latedef": false, | ||
"newcap": true, | ||
"noarg": true, | ||
"noempty": true, | ||
"nonbsp": true, | ||
"nonew": true, | ||
"plusplus": false, | ||
"quotmark": "single", | ||
"undef": true, | ||
"unused": true, | ||
"trailing": true | ||
"unused": false, | ||
"maxparams": 4, | ||
"maxdepth": 4, | ||
"maxlen": 140 | ||
} |
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
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,20 @@ | ||
'use strict'; | ||
|
||
const Joi = require('joi'); | ||
|
||
// who's on first importer requires just `datapath` and defaults `importVenues` to false | ||
const schema = Joi.object().keys({ | ||
datapath: Joi.string(), | ||
importVenues: Joi.boolean().default(false).truthy('yes').falsy('no').insensitive(true) | ||
}).requiredKeys('datapath').unknown(false); | ||
|
||
module.exports = { | ||
validate: function validate(config) { | ||
Joi.validate(config, schema, (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,113 @@ | ||
'use strict'; | ||
|
||
var tape = require('tape'); | ||
|
||
var configValidation = require('../src/configValidation'); | ||
|
||
tape('tests for looking up hierarchies', function(test) { | ||
test.test('config lacking datapath should throw error', function(t) { | ||
var config = { | ||
importVenues: true | ||
}; | ||
|
||
t.throws(function() { | ||
configValidation.validate(config); | ||
}, /"datapath" is required/); | ||
t.end(); | ||
|
||
}); | ||
|
||
test.test('config lacking importVenues should not throw error', function(t) { | ||
var config = { | ||
datapath: '/path/to/data' | ||
}; | ||
|
||
t.doesNotThrow(function() { | ||
configValidation.validate(config); | ||
}); | ||
t.end(); | ||
|
||
}); | ||
|
||
test.test('config with spurious keys should throw error', function(t) { | ||
var config = { | ||
datapath: '/path/to/data', | ||
importVenues: true, | ||
spurious_key: 'value' | ||
}; | ||
|
||
t.throws(function() { | ||
configValidation.validate(config); | ||
}, /"spurious_key" is not allowed/); | ||
t.end(); | ||
|
||
}); | ||
|
||
test.test('non-string datapath should throw error', function(t) { | ||
[null, 17, {}, [], true].forEach((value) => { | ||
var config = { | ||
datapath: value | ||
}; | ||
|
||
t.throws(function() { | ||
configValidation.validate(config); | ||
}, /"datapath" must be a string/); | ||
|
||
}); | ||
|
||
t.end(); | ||
|
||
}); | ||
|
||
test.test('non-boolean importVenues should throw error', function(t) { | ||
[null, 17, {}, [], 'string'].forEach((value) => { | ||
var config = { | ||
datapath: '/path/to/data', | ||
importVenues: value | ||
}; | ||
|
||
t.throws(function() { | ||
configValidation.validate(config); | ||
}, /"importVenues" must be a boolean/); | ||
|
||
}); | ||
|
||
t.end(); | ||
|
||
}); | ||
|
||
test.test('case-insensitive \'yes\' and true should be valid importVenues values', function(t) { | ||
[true, 'YeS', 'yEs'].forEach((value) => { | ||
var config = { | ||
datapath: '/path/to/data', | ||
importVenues: value | ||
}; | ||
|
||
t.doesNotThrow(function() { | ||
configValidation.validate(config); | ||
}); | ||
|
||
}); | ||
|
||
t.end(); | ||
|
||
}); | ||
|
||
test.test('case-insensitive \'no\' and false should be valid importVenues values', function(t) { | ||
[false, 'nO', 'No'].forEach((value) => { | ||
var config = { | ||
datapath: '/path/to/data', | ||
importVenues: value | ||
}; | ||
|
||
t.doesNotThrow(function() { | ||
configValidation.validate(config); | ||
}); | ||
|
||
}); | ||
|
||
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
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