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 );
// @todo: remove this hack
return JSON.parse( JSON.stringify( result ) );
return query.render( vs );
}
module.exports = generateQuery;

5
query/reverse.js

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

3
query/search.js

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

13
test/unit/query/autocomplete.js

@ -10,13 +10,6 @@ module.exports.tests.interface = function(test, common) {
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) {
test('valid lingustic-only autocomplete', function(t) {
@ -24,9 +17,10 @@ module.exports.tests.query = function(test, common) {
text: 'test'
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_only');
t.deepEqual(query, expected, 'valid autocomplete query');
t.deepEqual(compiled, expected, 'valid autocomplete query');
t.end();
});
@ -37,9 +31,10 @@ module.exports.tests.query = function(test, common) {
lon: -82.50622
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/autocomplete_linguistic_focus');
t.deepEqual(query, expected, 'valid autocomplete query');
t.deepEqual(compiled, expected, 'valid autocomplete query');
t.end();
});
};

15
test/unit/query/reverse.js

@ -3,14 +3,6 @@ var generate = require('../../../query/reverse');
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) {
test('valid interface', function(t) {
t.equal(typeof generate, 'function', 'valid function');
@ -24,8 +16,10 @@ module.exports.tests.query = function(test, common) {
lat: 29.49136, lon: -82.50622
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/reverse_standard');
t.deepEqual(query, expected, 'valid reverse query');
t.deepEqual(compiled, expected, 'valid reverse query');
t.end();
});
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
});
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();
});

21
test/unit/query/search.js

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

Loading…
Cancel
Save