|
|
|
@ -1,11 +1,11 @@
|
|
|
|
|
var sanitizer = require('../../../sanitizer/_synthesize_analysis'); |
|
|
|
|
var _ = require('lodash'); |
|
|
|
|
const sanitizer = require('../../../sanitizer/_synthesize_analysis'); |
|
|
|
|
const _ = require('lodash'); |
|
|
|
|
|
|
|
|
|
module.exports.tests = {}; |
|
|
|
|
|
|
|
|
|
module.exports.tests.text_parser = function(test, common) { |
|
|
|
|
test('all variables should be parsed', function(t) { |
|
|
|
|
var raw = { |
|
|
|
|
const raw = { |
|
|
|
|
query: ' \t query \t value \t ', |
|
|
|
|
address: ' \t address \t value \t ', |
|
|
|
|
neighbourhood: ' \t neighbourhood \t value \t ', |
|
|
|
@ -17,11 +17,10 @@ module.exports.tests.text_parser = function(test, common) {
|
|
|
|
|
country: ' \t country \t value \t ' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var clean = {}; |
|
|
|
|
const clean = {}; |
|
|
|
|
|
|
|
|
|
var expected_clean = { |
|
|
|
|
const expected_clean = { |
|
|
|
|
parsed_text: { |
|
|
|
|
query: 'query value', |
|
|
|
|
address: 'address value', |
|
|
|
|
neighbourhood: 'neighbourhood value', |
|
|
|
|
borough: 'borough value', |
|
|
|
@ -33,7 +32,7 @@ module.exports.tests.text_parser = function(test, common) {
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var messages = sanitizer(raw, clean); |
|
|
|
|
const messages = sanitizer(raw, clean); |
|
|
|
|
|
|
|
|
|
t.deepEquals(clean, expected_clean); |
|
|
|
|
t.deepEquals(messages.errors, [], 'no errors'); |
|
|
|
@ -48,8 +47,7 @@ module.exports.tests.text_parser = function(test, common) {
|
|
|
|
|
return _.sample([{}, [], false, '', ' \t ', 17, undefined]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var raw = { |
|
|
|
|
query: getInvalidValue(), |
|
|
|
|
const raw = { |
|
|
|
|
address: getInvalidValue(), |
|
|
|
|
neighbourhood: getInvalidValue(), |
|
|
|
|
borough: getInvalidValue(), |
|
|
|
@ -60,34 +58,34 @@ module.exports.tests.text_parser = function(test, common) {
|
|
|
|
|
country: getInvalidValue() |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var clean = {}; |
|
|
|
|
const clean = {}; |
|
|
|
|
|
|
|
|
|
var expected_clean = { |
|
|
|
|
const expected_clean = { |
|
|
|
|
parsed_text: {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var messages = sanitizer(raw, clean); |
|
|
|
|
const messages = sanitizer(raw, clean); |
|
|
|
|
|
|
|
|
|
t.deepEquals(clean, expected_clean); |
|
|
|
|
t.deepEquals(messages.errors, ['at least one of the following fields is required: ' + |
|
|
|
|
'query, address, neighbourhood, borough, city, county, state, postalcode, country'], 'no errors'); |
|
|
|
|
'address, neighbourhood, borough, city, county, state, postalcode, country'], 'no errors'); |
|
|
|
|
t.deepEquals(messages.warnings, [], 'no warnings'); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('no supplied fields should return error', function(t) { |
|
|
|
|
var raw = {}; |
|
|
|
|
const raw = {}; |
|
|
|
|
|
|
|
|
|
var clean = {}; |
|
|
|
|
const clean = {}; |
|
|
|
|
|
|
|
|
|
var expected_clean = { parsed_text: {} }; |
|
|
|
|
const expected_clean = { parsed_text: {} }; |
|
|
|
|
|
|
|
|
|
var messages = sanitizer(raw, clean); |
|
|
|
|
const messages = sanitizer(raw, clean); |
|
|
|
|
|
|
|
|
|
t.deepEquals(clean, expected_clean); |
|
|
|
|
t.deepEquals(messages.errors, ['at least one of the following fields is required: ' + |
|
|
|
|
'query, address, neighbourhood, borough, city, county, state, postalcode, country'], 'no errors'); |
|
|
|
|
'address, neighbourhood, borough, city, county, state, postalcode, country'], 'no errors'); |
|
|
|
|
t.deepEquals(messages.warnings, [], 'no warnings'); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
@ -100,7 +98,7 @@ module.exports.all = function (tape, common) {
|
|
|
|
|
return tape('sanitizer _synthesize_analysis: ' + name, testFunction); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for( var testCase in module.exports.tests ){ |
|
|
|
|
for( const testCase in module.exports.tests ){ |
|
|
|
|
module.exports.tests[testCase](test, common); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|