From a5ba251afe30a2db3b5e40f574e136546ade62c5 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Tue, 15 Sep 2015 14:06:35 -0400 Subject: [PATCH] Remove brittle test fixture from search sanitiser Some of the tests were checking the entire clean object, when they only cared about one tiny element. This made making changes really hard. --- test/unit/sanitiser/_text.js | 24 ------------------------ test/unit/sanitiser/search.js | 28 +++++++++------------------- 2 files changed, 9 insertions(+), 43 deletions(-) delete mode 100644 test/unit/sanitiser/_text.js diff --git a/test/unit/sanitiser/_text.js b/test/unit/sanitiser/_text.js deleted file mode 100644 index 370a4061..00000000 --- a/test/unit/sanitiser/_text.js +++ /dev/null @@ -1,24 +0,0 @@ - -var text = require('../../../sanitiser/_text'), - parser = require('../../../helper/query_parser'), - allLayers = [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood', - 'locality', 'local_admin', 'osmaddress', 'openaddresses' ], - defaultParsed= { }, - defaultClean = { text: 'test', - layers: allLayers, - size: 10, - parsed_text: defaultParsed, - lat:0, - lon:0 - }, - getTargetLayers = function(query) { - var address = parser.get_parsed_address(query); - return address.target_layer; - }; - - -module.exports = { - defaultParsed: defaultParsed, - defaultClean : defaultClean, - getTargetLayers: getTargetLayers -}; diff --git a/test/unit/sanitiser/search.js b/test/unit/sanitiser/search.js index e6aee6ac..cb7125a1 100644 --- a/test/unit/sanitiser/search.js +++ b/test/unit/sanitiser/search.js @@ -1,17 +1,8 @@ var search = require('../../../sanitiser/search'), - _text = require('../sanitiser/_text'), parser = require('../../../helper/query_parser'), - defaultParsed = _text.defaultParsed, sanitize = search.sanitize, middleware = search.middleware, - defaultError = 'invalid param \'text\': text length, must be >0', - defaultClean = { text: 'test', - types: { - }, - size: 10, - parsed_text: defaultParsed, - }; - + defaultError = 'invalid param \'text\': text length, must be >0'; // these are the default values you would expect when no input params are specified. // @todo: why is this different from $defaultClean? var emptyClean = { boundary: {}, private: false, size: 10, types: {} }; @@ -85,13 +76,13 @@ module.exports.tests.sanitize_text_with_delim = function(test, common) { test('valid texts with a comma', function(t) { texts.forEach( function( text ){ var req = { query: { text: text } }; - sanitize(req, function(){ - var expected = JSON.parse(JSON.stringify( defaultClean )); - expected.text = text; + sanitize( req, function( ){ + var expected_text = text; - expected.parsed_text = parser.get_parsed_address(text); + var expected_parsed_text = parser.get_parsed_address(text); t.equal(req.errors[0], undefined, 'no error'); - t.equal(req.clean.parsed_text.name, expected.parsed_text.name, 'clean name set correctly'); + t.equal(req.clean.parsed_text.name, expected_parsed_text.name, 'clean name set correctly'); + t.equal(req.clean.text, expected_text, 'text should match'); }); }); @@ -164,11 +155,10 @@ module.exports.tests.sanitize_lon = function(test, common) { test('valid lon', function(t) { lons.valid.forEach( function( lon ){ var req = { query: { text: 'test', 'focus.point.lat': 0, 'focus.point.lon': lon } }; - sanitize(req, function(){ - var expected = JSON.parse(JSON.stringify( defaultClean )); - expected.lon = parseFloat( lon ); + sanitize( req, function(){ + var expected_lon = parseFloat( lon ); t.equal(req.errors[0], undefined, 'no error'); - t.equal(req.clean.lon, expected.lon, 'clean set correctly (' + lon + ')'); + t.deepEqual(req.clean.lon, expected_lon, 'clean set correctly (' + lon + ')'); }); }); t.end();