mirror of https://github.com/pelias/api.git
Alex Loyko
7 years ago
2 changed files with 142 additions and 0 deletions
@ -0,0 +1,77 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
const _ = require('lodash'); |
||||||
|
const is_intersection_layer = require('../../../../controller/predicates/is_intersection_layer'); |
||||||
|
|
||||||
|
module.exports.tests = {}; |
||||||
|
|
||||||
|
module.exports.tests.interface = (test, common) => { |
||||||
|
test('valid interface', t => { |
||||||
|
t.ok(_.isFunction(is_intersection_layer), 'is_intersection_layer is a function'); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
module.exports.tests.true_conditions = (test, common) => { |
||||||
|
test('"Main & Broadway" should return true', t => { |
||||||
|
const req = {}; |
||||||
|
req.query = {}; |
||||||
|
req.query.text = 'Main & Broadway'; |
||||||
|
|
||||||
|
t.ok(is_intersection_layer(req)); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
|
||||||
|
test('"23rd and 5th" should return true', t => { |
||||||
|
const req = {}; |
||||||
|
req.query = {}; |
||||||
|
req.query.text = '23rd and 5th'; |
||||||
|
|
||||||
|
t.ok(is_intersection_layer(req)); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
|
||||||
|
test('"73rd& Bay pkwy" should return true', t => { |
||||||
|
const req = {}; |
||||||
|
req.query = {}; |
||||||
|
req.query.text = '73rd& Bay pkwy'; |
||||||
|
|
||||||
|
t.ok(is_intersection_layer(req)); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
|
||||||
|
test('"73rd&Broadway" should return true', t => { |
||||||
|
const req = {}; |
||||||
|
req.query = {}; |
||||||
|
req.query.text = '73rd&Bay pkwy'; |
||||||
|
|
||||||
|
t.ok(is_intersection_layer(req)); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
module.exports.tests.false_conditions = (test, common) => { |
||||||
|
test('undefined request should return false', t => { |
||||||
|
t.notOk(is_intersection_layer(undefined)); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
|
||||||
|
test('"Nostrand Avenue" should return false', t => { |
||||||
|
const req = {}; |
||||||
|
req.query = {}; |
||||||
|
req.query.text = 'Nostrand Avenue'; |
||||||
|
|
||||||
|
t.notOk(is_intersection_layer(req)); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
module.exports.all = (tape, common) => { |
||||||
|
function test(name, testFunction) { |
||||||
|
return tape(`GET /is_intersection_layer ${name}`, testFunction); |
||||||
|
} |
||||||
|
|
||||||
|
for( const testCase in module.exports.tests ){ |
||||||
|
module.exports.tests[testCase](test, common); |
||||||
|
} |
||||||
|
}; |
@ -0,0 +1,65 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
const _ = require('lodash'); |
||||||
|
var intersectionsParser = require('../../../helper/intersectionsParsing'); |
||||||
|
|
||||||
|
module.exports.tests = {}; |
||||||
|
|
||||||
|
module.exports.tests.interface = function (test) { |
||||||
|
test('valid interface', t => { |
||||||
|
t.equal(typeof intersectionsParser, 'function', 'parseIntersections is a function'); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
module.exports.tests.intersectionsParser = function (test) { |
||||||
|
|
||||||
|
test('parseIntersections', t => { |
||||||
|
t.deepEqual(intersectionsParser('72 and 18'), { street1: '72nd', street2: '18th'}, |
||||||
|
'intersectionsParser parsed "72 and 18" correctly!'); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
|
||||||
|
test('parseIntersections', t => { |
||||||
|
t.deepEqual(intersectionsParser('61 & Bay'), { street1: '61st', street2: 'bay'}, |
||||||
|
'intersectionsParser parsed "61 and Bay" correctly!'); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
|
||||||
|
test('parseIntersections', t => { |
||||||
|
t.deepEqual(intersectionsParser('73 & e5'), {street1: '73rd', street2: 'East 5th'}, |
||||||
|
'intersectionsParser parsed "73 and e5" correctly!'); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
|
||||||
|
test('parseIntersections', t => { |
||||||
|
t.deepEqual(intersectionsParser('25 & w5'), { street1: '25th', street2: 'West 5th'}, |
||||||
|
'intersectionsParser parsed "25 and w5" correctly!'); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
|
||||||
|
test('parseIntersections', t => { |
||||||
|
t.deepEqual(intersectionsParser('ne26 & nw5'), { street1: 'Northeast 26th', street2: 'Northwest 5th'}, |
||||||
|
'intersectionsParser parsed "26 and nw5" correctly!'); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
|
||||||
|
test('parseIntersections', t => { |
||||||
|
t.deepEqual(intersectionsParser('se26 & sw5'), { street1: 'Southeast 26th', street2: 'Southwest 5th'}, |
||||||
|
'intersectionsParser parsed "26 and nw5" correctly!'); |
||||||
|
t.end(); |
||||||
|
}); |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
module.exports.all = (tape, common) => { |
||||||
|
|
||||||
|
// this part I am not sure about. Subject to review
|
||||||
|
function test(name, testFunction) { |
||||||
|
return tape(`intersections: ${name}`, testFunction); |
||||||
|
} |
||||||
|
|
||||||
|
for( const testCase in module.exports.tests ){ |
||||||
|
module.exports.tests[testCase](test, common); |
||||||
|
} |
||||||
|
}; |
Loading…
Reference in new issue