Browse Source

move stringify logic to tests, code clean up

pull/242/head
Peter Johnson 9 years ago
parent
commit
d568c031a3
  1. 5
      query/autocomplete.js
  2. 5
      query/reverse.js
  3. 3
      query/search.js
  4. 13
      test/unit/query/autocomplete.js
  5. 15
      test/unit/query/reverse.js
  6. 21
      test/unit/query/search.js

5
query/autocomplete.js

@ -37,10 +37,7 @@ function generateQuery( clean ){
}); });
} }
var result = query.render( vs ); return query.render( vs );
// @todo: remove this hack
return JSON.parse( JSON.stringify( result ) );
} }
module.exports = generateQuery; module.exports = generateQuery;

5
query/reverse.js

@ -43,10 +43,7 @@ function generateQuery( clean ){
}); });
} }
var result = query.render( vs ); return query.render( vs );
// @todo: remove this hack
return JSON.parse( JSON.stringify( result ) );
} }
module.exports = generateQuery; module.exports = generateQuery;

3
query/search.js

@ -187,8 +187,7 @@ function generateQuery( clean ){
// @todo: remove unnessesary sort conditions // @todo: remove unnessesary sort conditions
result.sort = result.sort.concat( sort( clean ) ); result.sort = result.sort.concat( sort( clean ) );
// @todo: remove this hack return result;
return JSON.parse( JSON.stringify( result ) );
} }
module.exports = generateQuery; module.exports = generateQuery;

13
test/unit/query/autocomplete.js

@ -10,13 +10,6 @@ module.exports.tests.interface = function(test, common) {
t.end(); t.end();
}); });
}; };
function foo( a, b ){
console.log( '----------------' );
console.log( JSON.stringify( a, null, 2 ) );
console.log( '----------------' );
console.log( JSON.stringify( b, null, 2 ) );
console.log( '----------------' );
}
module.exports.tests.query = function(test, common) { module.exports.tests.query = function(test, common) {
test('valid lingustic-only autocomplete', function(t) { test('valid lingustic-only autocomplete', function(t) {
@ -24,9 +17,10 @@ module.exports.tests.query = function(test, common) {
text: 'test' text: 'test'
}); });
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_only'); var expected = require('../fixture/autocomplete_linguistic_only');
t.deepEqual(query, expected, 'valid autocomplete query'); t.deepEqual(compiled, expected, 'valid autocomplete query');
t.end(); t.end();
}); });
@ -37,9 +31,10 @@ module.exports.tests.query = function(test, common) {
lon: -82.50622 lon: -82.50622
}); });
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_focus'); var expected = require('../fixture/autocomplete_linguistic_focus');
t.deepEqual(query, expected, 'valid autocomplete query'); t.deepEqual(compiled, expected, 'valid autocomplete query');
t.end(); t.end();
}); });
}; };

15
test/unit/query/reverse.js

@ -3,14 +3,6 @@ var generate = require('../../../query/reverse');
module.exports.tests = {}; module.exports.tests = {};
function debug( a,b ){
console.log( '----------------------' );
console.log( JSON.stringify( a, null, 2 ) );
console.log( '----------------------' );
console.log( JSON.stringify( b, null, 2 ) );
console.log( '----------------------' );
}
module.exports.tests.interface = function(test, common) { module.exports.tests.interface = function(test, common) {
test('valid interface', function(t) { test('valid interface', function(t) {
t.equal(typeof generate, 'function', 'valid function'); t.equal(typeof generate, 'function', 'valid function');
@ -24,8 +16,10 @@ module.exports.tests.query = function(test, common) {
lat: 29.49136, lon: -82.50622 lat: 29.49136, lon: -82.50622
}); });
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/reverse_standard'); var expected = require('../fixture/reverse_standard');
t.deepEqual(query, expected, 'valid reverse query');
t.deepEqual(compiled, expected, 'valid reverse query');
t.end(); t.end();
}); });
test('size fuzz test', function(t) { test('size fuzz test', function(t) {
@ -36,7 +30,8 @@ module.exports.tests.query = function(test, common) {
lat: 29.49136, lon: -82.50622, size: size lat: 29.49136, lon: -82.50622, size: size
}); });
t.equal( query.size, size ? size : 1, 'valid reverse query for size: '+ size); var compiled = JSON.parse( JSON.stringify( query ) );
t.equal( compiled.size, size ? size : 1, 'valid reverse query for size: '+ size);
}); });
t.end(); t.end();
}); });

21
test/unit/query/search.js

@ -27,10 +27,11 @@ module.exports.tests.query = function(test, common) {
layers: ['test'] layers: ['test']
}); });
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus_bbox'); var expected = require('../fixture/search_linguistic_focus_bbox');
expected.sort = sort; expected.sort = sort;
t.deepEqual(query, expected, 'valid search query'); t.deepEqual(compiled, expected, 'valid search query');
t.end(); t.end();
}); });
@ -46,10 +47,11 @@ module.exports.tests.query = function(test, common) {
layers: ['test'] layers: ['test']
}); });
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_bbox'); var expected = require('../fixture/search_linguistic_bbox');
expected.sort = sort; expected.sort = sort;
t.deepEqual(query, expected, 'valid search query'); t.deepEqual(compiled, expected, 'valid search query');
t.end(); t.end();
}); });
@ -59,10 +61,11 @@ module.exports.tests.query = function(test, common) {
layers: ['test'] layers: ['test']
}); });
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_only'); var expected = require('../fixture/search_linguistic_only');
expected.sort = sort; expected.sort = sort;
t.deepEqual(query, expected, 'valid search query'); t.deepEqual(compiled, expected, 'valid search query');
t.end(); t.end();
}); });
@ -73,10 +76,11 @@ module.exports.tests.query = function(test, common) {
layers: ['test'] layers: ['test']
}); });
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus'); var expected = require('../fixture/search_linguistic_focus');
expected.sort = sort; expected.sort = sort;
t.deepEqual(query, expected, 'valid search query'); t.deepEqual(compiled, expected, 'valid search query');
t.end(); t.end();
}); });
@ -90,10 +94,11 @@ module.exports.tests.query = function(test, common) {
parsed_text: parser.get_parsed_address(address), parsed_text: parser.get_parsed_address(address),
}); });
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_full_address'); var expected = require('../fixture/search_full_address');
expected.sort = sort; expected.sort = sort;
t.deepEqual(query, expected, 'valid search query'); t.deepEqual(compiled, expected, 'valid search query');
t.end(); t.end();
}); });
@ -107,10 +112,11 @@ module.exports.tests.query = function(test, common) {
parsed_text: parser.get_parsed_address(partial_address), parsed_text: parser.get_parsed_address(partial_address),
}); });
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_partial_address'); var expected = require('../fixture/search_partial_address');
expected.sort = sort; expected.sort = sort;
t.deepEqual(query, expected, 'valid search query'); t.deepEqual(compiled, expected, 'valid search query');
t.end(); t.end();
}); });
@ -124,10 +130,11 @@ module.exports.tests.query = function(test, common) {
parsed_text: parser.get_parsed_address(partial_address), parsed_text: parser.get_parsed_address(partial_address),
}); });
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_regions_address'); var expected = require('../fixture/search_regions_address');
expected.sort = sort; expected.sort = sort;
t.deepEqual(query, expected, 'valid search query'); t.deepEqual(compiled, expected, 'valid search query');
t.end(); t.end();
}); });

Loading…
Cancel
Save