mirror of https://github.com/pelias/api.git
Stephen K Hess
8 years ago
committed by
GitHub
23 changed files with 1322 additions and 808 deletions
@ -1,14 +0,0 @@ |
|||||||
var config = require( 'pelias-config' ).generate().esclient; |
|
||||||
var Backend = require('geopipes-elasticsearch-backend'), |
|
||||||
client = require('elasticsearch').Client(config), |
|
||||||
backends = {}; |
|
||||||
|
|
||||||
function getBackend( index, type ){ |
|
||||||
var key = ( index + ':' + type ); |
|
||||||
if( !backends[key] ){ |
|
||||||
backends[key] = new Backend( client, index, type ); |
|
||||||
} |
|
||||||
return backends[key]; |
|
||||||
} |
|
||||||
|
|
||||||
module.exports = getBackend; |
|
@ -1,129 +1,372 @@ |
|||||||
var setup = require('../../../controller/place'), |
'use strict'; |
||||||
mockBackend = require('../mock/backend'); |
|
||||||
|
const setup = require('../../../controller/search'); |
||||||
|
const proxyquire = require('proxyquire').noCallThru(); |
||||||
|
|
||||||
module.exports.tests = {}; |
module.exports.tests = {}; |
||||||
|
|
||||||
module.exports.tests.interface = function(test, common) { |
module.exports.tests.interface = (test, common) => { |
||||||
test('valid interface', function(t) { |
test('valid interface', (t) => { |
||||||
t.equal(typeof setup, 'function', 'setup is a function'); |
t.equal(typeof setup, 'function', 'setup is a function'); |
||||||
t.equal(typeof setup(), 'function', 'setup returns a controller'); |
t.equal(typeof setup(), 'function', 'setup returns a controller'); |
||||||
t.end(); |
t.end(); |
||||||
}); |
}); |
||||||
}; |
}; |
||||||
|
|
||||||
// reminder: this is only the api subsection of the full config
|
module.exports.tests.success = (test, common) => { |
||||||
var fakeDefaultConfig = { |
test('successful request to search service should set data and meta', (t) => { |
||||||
indexName: 'pelias' |
const config = { |
||||||
|
indexName: 'indexName value' |
||||||
}; |
}; |
||||||
|
const esclient = 'this is the esclient'; |
||||||
|
|
||||||
// functionally test controller (backend success)
|
// request timeout messages willl be written here
|
||||||
module.exports.tests.functional_success = function(test, common) { |
const infoMesssages = []; |
||||||
|
|
||||||
// expected geojson features for 'client/place/ok/1' fixture
|
// a controller that validates the esclient and cmd that was passed to the search service
|
||||||
var expected = [{ |
const controller = proxyquire('../../../controller/place', { |
||||||
type: 'Feature', |
'../service/mget': (esclient, query, callback) => { |
||||||
geometry: { |
t.equal(esclient, 'this is the esclient'); |
||||||
type: 'Point', |
t.deepEqual(query, [ |
||||||
coordinates: [ -50.5, 100.1 ] |
{ |
||||||
}, |
_index: 'indexName value', |
||||||
properties: { |
_type: 'layer1', |
||||||
id: 'myid1', |
_id: 'id1' |
||||||
layer: 'mytype1', |
|
||||||
text: 'test name1, city1, state1' |
|
||||||
} |
|
||||||
}, { |
|
||||||
type: 'Feature', |
|
||||||
geometry: { |
|
||||||
type: 'Point', |
|
||||||
coordinates: [ -51.5, 100.2 ] |
|
||||||
}, |
}, |
||||||
properties: { |
{ |
||||||
id: 'myid2', |
_index: 'indexName value', |
||||||
layer: 'mytype2', |
_type: 'layer2', |
||||||
text: 'test name2, city2, state2' |
_id: 'id2' |
||||||
} |
} |
||||||
}]; |
]); |
||||||
|
|
||||||
test('functional success', function(t) { |
const docs = [{}, {}]; |
||||||
var backend = mockBackend( 'client/mget/ok/1', function( cmd ){ |
|
||||||
t.deepEqual(cmd, { body: { docs: [ { _id: 123, _index: 'pelias', _type: [ 'a' ] } ] } }, 'correct backend command'); |
callback(undefined, docs); |
||||||
}); |
} |
||||||
var controller = setup( fakeDefaultConfig, backend ); |
})(config, esclient); |
||||||
var res = { |
|
||||||
status: function( code ){ |
const req = { |
||||||
t.equal(code, 200, 'status set'); |
clean: { |
||||||
return res; |
ids: [ |
||||||
|
{ |
||||||
|
id: 'id1', |
||||||
|
layers: 'layer1' |
||||||
}, |
}, |
||||||
json: function( json ){ |
{ |
||||||
t.equal(typeof json, 'object', 'returns json'); |
id: 'id2', |
||||||
t.equal(typeof json.date, 'number', 'date set'); |
layers: 'layer2' |
||||||
t.equal(json.type, 'FeatureCollection', 'valid geojson'); |
|
||||||
t.true(Array.isArray(json.features), 'features is array'); |
|
||||||
t.deepEqual(json.features, expected, 'values correctly mapped'); |
|
||||||
} |
} |
||||||
|
] |
||||||
|
}, |
||||||
|
errors: [], |
||||||
|
warnings: [] |
||||||
}; |
}; |
||||||
var req = { clean: { ids: [ {'id' : 123, layers: [ 'a' ] } ] }, errors: [], warnings: [] }; |
const res = {}; |
||||||
var next = function next() { |
|
||||||
t.equal(req.errors.length, 0, 'next was called without error'); |
const next = () => { |
||||||
|
t.deepEqual(req.errors, []); |
||||||
|
t.deepEqual(req.warnings, []); |
||||||
|
t.deepEquals(res.data, [{}, {}]); |
||||||
t.end(); |
t.end(); |
||||||
}; |
}; |
||||||
|
|
||||||
controller(req, res, next); |
controller(req, res, next); |
||||||
|
|
||||||
}); |
}); |
||||||
|
|
||||||
test('functional success with custom index name', function(t) { |
|
||||||
var fakeCustomizedConfig = { |
|
||||||
indexName: 'alternateindexname' |
|
||||||
}; |
}; |
||||||
|
|
||||||
var backend = mockBackend( 'client/mget/ok/1', function( cmd ){ |
module.exports.tests.error_conditions = (test, common) => { |
||||||
t.deepEqual(cmd, { body: { docs: [ { _id: 123, _index: 'alternateindexname', _type: [ 'a' ] } ] } }, 'correct backend command'); |
test('non-empty req.errors should ', (t) => { |
||||||
|
const esclient = () => { |
||||||
|
throw new Error('esclient should not have been called'); |
||||||
|
}; |
||||||
|
const controller = setup( {}, esclient ); |
||||||
|
|
||||||
|
// the existence of `errors` means that a sanitizer detected an error,
|
||||||
|
// so don't call the esclient
|
||||||
|
const req = { |
||||||
|
errors: ['error'] |
||||||
|
}; |
||||||
|
const res = { }; |
||||||
|
|
||||||
|
t.doesNotThrow(() => { |
||||||
|
controller(req, res, () => {}); |
||||||
|
}); |
||||||
|
t.end(); |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
test('mgetService returning error should add to req.errors and ignore docs', (t) => { |
||||||
|
const config = { |
||||||
|
indexName: 'indexName value' |
||||||
|
}; |
||||||
|
const esclient = 'this is the esclient'; |
||||||
|
|
||||||
|
// request timeout messages willl be written here
|
||||||
|
const infoMesssages = []; |
||||||
|
|
||||||
|
const nonTimeoutError = { |
||||||
|
status: 500, |
||||||
|
displayName: 'InternalServerError', |
||||||
|
message: 'an internal server error occurred' |
||||||
|
}; |
||||||
|
|
||||||
|
// a controller that validates the esclient and cmd that was passed to the search service
|
||||||
|
const controller = proxyquire('../../../controller/place', { |
||||||
|
'../service/mget': (esclient, query, callback) => { |
||||||
|
const docs = [{}, {}]; |
||||||
|
|
||||||
|
callback(nonTimeoutError, docs); |
||||||
|
} |
||||||
|
})(config, esclient); |
||||||
|
|
||||||
|
const req = { |
||||||
|
clean: { |
||||||
|
ids: [ |
||||||
|
{ |
||||||
|
id: 'id1', |
||||||
|
layers: 'layer1' |
||||||
|
} |
||||||
|
] |
||||||
|
}, |
||||||
|
errors: [], |
||||||
|
warnings: [] |
||||||
|
}; |
||||||
|
const res = {}; |
||||||
|
|
||||||
|
const next = () => { |
||||||
|
t.deepEqual(req.errors, [nonTimeoutError.message]); |
||||||
|
t.deepEqual(req.warnings, []); |
||||||
|
t.deepEquals(res.data, undefined); |
||||||
|
t.end(); |
||||||
|
}; |
||||||
|
|
||||||
|
controller(req, res, next); |
||||||
|
|
||||||
}); |
}); |
||||||
var controller = setup( fakeCustomizedConfig, backend ); |
|
||||||
var res = { |
}; |
||||||
status: function( code ){ |
|
||||||
t.equal(code, 200, 'status set'); |
module.exports.tests.timeout = function(test, common) { |
||||||
return res; |
test('default # of request timeout retries should be 3', (t) => { |
||||||
|
const config = { |
||||||
|
indexName: 'indexName value' |
||||||
|
}; |
||||||
|
const esclient = 'this is the esclient'; |
||||||
|
|
||||||
|
let searchServiceCallCount = 0; |
||||||
|
|
||||||
|
const timeoutError = { |
||||||
|
status: 408, |
||||||
|
displayName: 'RequestTimeout', |
||||||
|
message: 'Request Timeout after 17ms' |
||||||
|
}; |
||||||
|
|
||||||
|
// request timeout messages willl be written here
|
||||||
|
const infoMesssages = []; |
||||||
|
|
||||||
|
// a controller that validates the esclient and cmd that was passed to the search service
|
||||||
|
const controller = proxyquire('../../../controller/place', { |
||||||
|
'../service/mget': (esclient, cmd, callback) => { |
||||||
|
// not that the searchService got called
|
||||||
|
searchServiceCallCount++; |
||||||
|
|
||||||
|
callback(timeoutError); |
||||||
|
}, |
||||||
|
'pelias-logger': { |
||||||
|
get: (service) => { |
||||||
|
t.equal(service, 'api'); |
||||||
|
return { |
||||||
|
info: (msg) => { |
||||||
|
infoMesssages.push(msg); |
||||||
}, |
}, |
||||||
json: function( json ){ |
debug: () => {} |
||||||
t.equal(typeof json, 'object', 'returns json'); |
}; |
||||||
t.equal(typeof json.date, 'number', 'date set'); |
} |
||||||
t.equal(json.type, 'FeatureCollection', 'valid geojson'); |
} |
||||||
t.true(Array.isArray(json.features), 'features is array'); |
})(config, esclient); |
||||||
t.deepEqual(json.features, expected, 'values correctly mapped'); |
|
||||||
|
const req = { |
||||||
|
clean: { |
||||||
|
ids: [ |
||||||
|
{ |
||||||
|
id: 'id1', |
||||||
|
layers: 'layer1' |
||||||
|
} |
||||||
|
] |
||||||
|
}, |
||||||
|
errors: [], |
||||||
|
warnings: [] |
||||||
|
}; |
||||||
|
const res = {}; |
||||||
|
|
||||||
|
const next = () => { |
||||||
|
t.equal(searchServiceCallCount, 3+1); |
||||||
|
|
||||||
|
t.ok(infoMesssages.indexOf('request timed out on attempt 1, retrying') !== -1); |
||||||
|
t.ok(infoMesssages.indexOf('request timed out on attempt 2, retrying') !== -1); |
||||||
|
t.ok(infoMesssages.indexOf('request timed out on attempt 3, retrying') !== -1); |
||||||
|
|
||||||
|
t.deepEqual(req.errors, [timeoutError.message]); |
||||||
|
t.deepEqual(res, {}); |
||||||
|
t.end(); |
||||||
|
}; |
||||||
|
|
||||||
|
controller(req, res, next); |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
test('explicit apiConfig.requestRetries should retry that many times', (t) => { |
||||||
|
const config = { |
||||||
|
indexName: 'indexName value', |
||||||
|
requestRetries: 17 |
||||||
|
}; |
||||||
|
const esclient = 'this is the esclient'; |
||||||
|
|
||||||
|
let searchServiceCallCount = 0; |
||||||
|
|
||||||
|
const timeoutError = { |
||||||
|
status: 408, |
||||||
|
displayName: 'RequestTimeout', |
||||||
|
message: 'Request Timeout after 17ms' |
||||||
|
}; |
||||||
|
|
||||||
|
// a controller that validates the esclient and cmd that was passed to the search service
|
||||||
|
const controller = proxyquire('../../../controller/place', { |
||||||
|
'../service/mget': (esclient, cmd, callback) => { |
||||||
|
// not that the searchService got called
|
||||||
|
searchServiceCallCount++; |
||||||
|
|
||||||
|
callback(timeoutError); |
||||||
|
} |
||||||
|
})(config, esclient); |
||||||
|
|
||||||
|
const req = { |
||||||
|
clean: { |
||||||
|
ids: [ |
||||||
|
{ |
||||||
|
id: 'id1', |
||||||
|
layers: 'layer1' |
||||||
} |
} |
||||||
|
] |
||||||
|
}, |
||||||
|
errors: [], |
||||||
|
warnings: [] |
||||||
}; |
}; |
||||||
var req = { clean: { ids: [ {'id' : 123, layers: [ 'a' ] } ] }, errors: [], warnings: [] }; |
const res = {}; |
||||||
var next = function next() { |
|
||||||
t.equal(req.errors.length, 0, 'next was called without error'); |
const next = () => { |
||||||
|
t.equal(searchServiceCallCount, 17+1); |
||||||
t.end(); |
t.end(); |
||||||
}; |
}; |
||||||
|
|
||||||
controller(req, res, next); |
controller(req, res, next); |
||||||
|
|
||||||
}); |
}); |
||||||
|
|
||||||
|
test('only status code 408 should be considered a retryable request', (t) => { |
||||||
|
const config = { |
||||||
|
indexName: 'indexName value' |
||||||
|
}; |
||||||
|
const esclient = 'this is the esclient'; |
||||||
|
|
||||||
|
let searchServiceCallCount = 0; |
||||||
|
|
||||||
|
const nonTimeoutError = { |
||||||
|
status: 500, |
||||||
|
displayName: 'InternalServerError', |
||||||
|
message: 'an internal server error occurred' |
||||||
|
}; |
||||||
|
|
||||||
|
// a controller that validates the esclient and cmd that was passed to the search service
|
||||||
|
const controller = proxyquire('../../../controller/place', { |
||||||
|
'../service/mget': (esclient, cmd, callback) => { |
||||||
|
// not that the searchService got called
|
||||||
|
searchServiceCallCount++; |
||||||
|
|
||||||
|
callback(nonTimeoutError); |
||||||
|
} |
||||||
|
})(config, esclient); |
||||||
|
|
||||||
|
const req = { |
||||||
|
clean: { |
||||||
|
ids: [ |
||||||
|
{ |
||||||
|
id: 'id1', |
||||||
|
layers: 'layer1' |
||||||
|
} |
||||||
|
] |
||||||
|
}, |
||||||
|
errors: [], |
||||||
|
warnings: [] |
||||||
|
}; |
||||||
|
const res = {}; |
||||||
|
|
||||||
|
const next = () => { |
||||||
|
t.equal(searchServiceCallCount, 1); |
||||||
|
t.deepEqual(req.errors, [nonTimeoutError.message]); |
||||||
|
t.end(); |
||||||
}; |
}; |
||||||
|
|
||||||
// functionally test controller (backend failure)
|
controller(req, res, next); |
||||||
module.exports.tests.functional_failure = function(test, common) { |
|
||||||
test('functional failure', function(t) { |
|
||||||
var backend = mockBackend( 'client/mget/fail/1', function( cmd ){ |
|
||||||
t.deepEqual(cmd, { body: { docs: [ { _id: 123, _index: 'pelias', _type: ['b'] } ] } }, 'correct backend command'); |
|
||||||
}); |
}); |
||||||
var controller = setup( fakeDefaultConfig, backend ); |
|
||||||
var req = { clean: { ids: [ {'id' : 123, layers: [ 'b' ] } ] }, errors: [], warnings: [] }; |
test('string error should not retry and be logged as-is', (t) => { |
||||||
var next = function( message ){ |
const config = { |
||||||
t.equal(req.errors[0],'a backend error occurred','error passed to errorHandler'); |
indexName: 'indexName value' |
||||||
|
}; |
||||||
|
const esclient = 'this is the esclient'; |
||||||
|
|
||||||
|
let searchServiceCallCount = 0; |
||||||
|
|
||||||
|
const stringTypeError = 'this is an error string'; |
||||||
|
|
||||||
|
// a controller that validates the esclient and cmd that was passed to the search service
|
||||||
|
const controller = proxyquire('../../../controller/place', { |
||||||
|
'../service/mget': (esclient, cmd, callback) => { |
||||||
|
// not that the searchService got called
|
||||||
|
searchServiceCallCount++; |
||||||
|
|
||||||
|
callback(stringTypeError); |
||||||
|
} |
||||||
|
})(config, esclient); |
||||||
|
|
||||||
|
const req = { |
||||||
|
clean: { |
||||||
|
ids: [ |
||||||
|
{ |
||||||
|
id: 'id1', |
||||||
|
layers: 'layer1' |
||||||
|
} |
||||||
|
] |
||||||
|
}, |
||||||
|
errors: [], |
||||||
|
warnings: [] |
||||||
|
}; |
||||||
|
const res = {}; |
||||||
|
|
||||||
|
const next = () => { |
||||||
|
t.equal(searchServiceCallCount, 1); |
||||||
|
t.deepEqual(req.errors, [stringTypeError]); |
||||||
t.end(); |
t.end(); |
||||||
}; |
}; |
||||||
controller(req, undefined, next ); |
|
||||||
|
controller(req, res, next); |
||||||
|
|
||||||
}); |
}); |
||||||
|
|
||||||
}; |
}; |
||||||
|
|
||||||
module.exports.all = function (tape, common) { |
module.exports.all = (tape, common) => { |
||||||
|
|
||||||
function test(name, testFunction) { |
function test(name, testFunction) { |
||||||
return tape('GET /place ' + name, testFunction); |
return tape('GET /place ' + name, testFunction); |
||||||
} |
} |
||||||
|
|
||||||
for( var testCase in module.exports.tests ){ |
for( const testCase in module.exports.tests ){ |
||||||
module.exports.tests[testCase](test, common); |
module.exports.tests[testCase](test, common); |
||||||
} |
} |
||||||
}; |
}; |
||||||
|
@ -1,251 +0,0 @@ |
|||||||
{ |
|
||||||
"ABW": "Aruba", |
|
||||||
"AFG": "Afghanistan", |
|
||||||
"AGO": "Angola", |
|
||||||
"AIA": "Anguilla", |
|
||||||
"ALA": "Ă…land Islands", |
|
||||||
"ALB": "Albania", |
|
||||||
"AND": "Andorra", |
|
||||||
"ARE": "United Arab Emirates", |
|
||||||
"ARG": "Argentina", |
|
||||||
"ARM": "Armenia", |
|
||||||
"ASM": "American Samoa", |
|
||||||
"ATA": "Antarctica", |
|
||||||
"ATF": "French Southern Territories", |
|
||||||
"ATG": "Antigua and Barbuda", |
|
||||||
"AUS": "Australia", |
|
||||||
"AUT": "Austria", |
|
||||||
"AZE": "Azerbaijan", |
|
||||||
"BDI": "Burundi", |
|
||||||
"BEL": "Belgium", |
|
||||||
"BEN": "Benin", |
|
||||||
"BES": "Bonaire, Sint Eustatius and Saba", |
|
||||||
"BFA": "Burkina Faso", |
|
||||||
"BGD": "Bangladesh", |
|
||||||
"BGR": "Bulgaria", |
|
||||||
"BHR": "Bahrain", |
|
||||||
"BHS": "Bahamas", |
|
||||||
"BIH": "Bosnia and Herzegovina", |
|
||||||
"BLM": "Saint Barthélemy", |
|
||||||
"BLR": "Belarus", |
|
||||||
"BLZ": "Belize", |
|
||||||
"BMU": "Bermuda", |
|
||||||
"BOL": "Bolivia, Plurinational State of", |
|
||||||
"BRA": "Brazil", |
|
||||||
"BRB": "Barbados", |
|
||||||
"BRN": "Brunei Darussalam", |
|
||||||
"BTN": "Bhutan", |
|
||||||
"BVT": "Bouvet Island", |
|
||||||
"BWA": "Botswana", |
|
||||||
"CAF": "Central African Republic", |
|
||||||
"CAN": "Canada", |
|
||||||
"CCK": "Cocos (Keeling) Islands", |
|
||||||
"CHE": "Switzerland", |
|
||||||
"CHL": "Chile", |
|
||||||
"CHN": "China", |
|
||||||
"CIV": "CĂ´te d'Ivoire", |
|
||||||
"CMR": "Cameroon", |
|
||||||
"COD": "Congo, the Democratic Republic of the", |
|
||||||
"COG": "Congo", |
|
||||||
"COK": "Cook Islands", |
|
||||||
"COL": "Colombia", |
|
||||||
"COM": "Comoros", |
|
||||||
"CPV": "Cabo Verde", |
|
||||||
"CRI": "Costa Rica", |
|
||||||
"CUB": "Cuba", |
|
||||||
"CUW": "Curaçao", |
|
||||||
"CXR": "Christmas Island", |
|
||||||
"CYM": "Cayman Islands", |
|
||||||
"CYP": "Cyprus", |
|
||||||
"CZE": "Czech Republic", |
|
||||||
"DEU": "Germany", |
|
||||||
"DJI": "Djibouti", |
|
||||||
"DMA": "Dominica", |
|
||||||
"DNK": "Denmark", |
|
||||||
"DOM": "Dominican Republic", |
|
||||||
"DZA": "Algeria", |
|
||||||
"ECU": "Ecuador", |
|
||||||
"EGY": "Egypt", |
|
||||||
"ERI": "Eritrea", |
|
||||||
"ESH": "Western Sahara", |
|
||||||
"ESP": "Spain", |
|
||||||
"EST": "Estonia", |
|
||||||
"ETH": "Ethiopia", |
|
||||||
"FIN": "Finland", |
|
||||||
"FJI": "Fiji", |
|
||||||
"FLK": "Falkland Islands (Malvinas)", |
|
||||||
"FRA": "France", |
|
||||||
"FRO": "Faroe Islands", |
|
||||||
"FSM": "Micronesia, Federated States of", |
|
||||||
"GAB": "Gabon", |
|
||||||
"GBR": "United Kingdom", |
|
||||||
"GEO": "Georgia", |
|
||||||
"GGY": "Guernsey", |
|
||||||
"GHA": "Ghana", |
|
||||||
"GIB": "Gibraltar", |
|
||||||
"GIN": "Guinea", |
|
||||||
"GLP": "Guadeloupe", |
|
||||||
"GMB": "Gambia", |
|
||||||
"GNB": "Guinea-Bissau", |
|
||||||
"GNQ": "Equatorial Guinea", |
|
||||||
"GRC": "Greece", |
|
||||||
"GRD": "Grenada", |
|
||||||
"GRL": "Greenland", |
|
||||||
"GTM": "Guatemala", |
|
||||||
"GUF": "French Guiana", |
|
||||||
"GUM": "Guam", |
|
||||||
"GUY": "Guyana", |
|
||||||
"HKG": "Hong Kong", |
|
||||||
"HMD": "Heard Island and McDonald Islands", |
|
||||||
"HND": "Honduras", |
|
||||||
"HRV": "Croatia", |
|
||||||
"HTI": "Haiti", |
|
||||||
"HUN": "Hungary", |
|
||||||
"IDN": "Indonesia", |
|
||||||
"IMN": "Isle of Man", |
|
||||||
"IND": "India", |
|
||||||
"IOT": "British Indian Ocean Territory", |
|
||||||
"IRL": "Ireland", |
|
||||||
"IRN": "Iran, Islamic Republic of", |
|
||||||
"IRQ": "Iraq", |
|
||||||
"ISL": "Iceland", |
|
||||||
"ISR": "Israel", |
|
||||||
"ITA": "Italy", |
|
||||||
"JAM": "Jamaica", |
|
||||||
"JEY": "Jersey", |
|
||||||
"JOR": "Jordan", |
|
||||||
"JPN": "Japan", |
|
||||||
"KAZ": "Kazakhstan", |
|
||||||
"KEN": "Kenya", |
|
||||||
"KGZ": "Kyrgyzstan", |
|
||||||
"KHM": "Cambodia", |
|
||||||
"KIR": "Kiribati", |
|
||||||
"KNA": "Saint Kitts and Nevis", |
|
||||||
"KOR": "Korea, Republic of", |
|
||||||
"KWT": "Kuwait", |
|
||||||
"LAO": "Lao People's Democratic Republic", |
|
||||||
"LBN": "Lebanon", |
|
||||||
"LBR": "Liberia", |
|
||||||
"LBY": "Libya", |
|
||||||
"LCA": "Saint Lucia", |
|
||||||
"LIE": "Liechtenstein", |
|
||||||
"LKA": "Sri Lanka", |
|
||||||
"LSO": "Lesotho", |
|
||||||
"LTU": "Lithuania", |
|
||||||
"LUX": "Luxembourg", |
|
||||||
"LVA": "Latvia", |
|
||||||
"MAC": "Macao", |
|
||||||
"MAF": "Saint Martin (French part)", |
|
||||||
"MAR": "Morocco", |
|
||||||
"MCO": "Monaco", |
|
||||||
"MDA": "Moldova, Republic of", |
|
||||||
"MDG": "Madagascar", |
|
||||||
"MDV": "Maldives", |
|
||||||
"MEX": "Mexico", |
|
||||||
"MHL": "Marshall Islands", |
|
||||||
"MKD": "Macedonia, the former Yugoslav Republic of", |
|
||||||
"MLI": "Mali", |
|
||||||
"MLT": "Malta", |
|
||||||
"MMR": "Myanmar", |
|
||||||
"MNE": "Montenegro", |
|
||||||
"MNG": "Mongolia", |
|
||||||
"MNP": "Northern Mariana Islands", |
|
||||||
"MOZ": "Mozambique", |
|
||||||
"MRT": "Mauritania", |
|
||||||
"MSR": "Montserrat", |
|
||||||
"MTQ": "Martinique", |
|
||||||
"MUS": "Mauritius", |
|
||||||
"MWI": "Malawi", |
|
||||||
"MYS": "Malaysia", |
|
||||||
"MYT": "Mayotte", |
|
||||||
"NAM": "Namibia", |
|
||||||
"NCL": "New Caledonia", |
|
||||||
"NER": "Niger", |
|
||||||
"NFK": "Norfolk Island", |
|
||||||
"NGA": "Nigeria", |
|
||||||
"NIC": "Nicaragua", |
|
||||||
"NIU": "Niue", |
|
||||||
"NLD": "Netherlands", |
|
||||||
"NOR": "Norway", |
|
||||||
"NPL": "Nepal", |
|
||||||
"NRU": "Nauru", |
|
||||||
"NZL": "New Zealand", |
|
||||||
"OMN": "Oman", |
|
||||||
"PAK": "Pakistan", |
|
||||||
"PAN": "Panama", |
|
||||||
"PCN": "Pitcairn", |
|
||||||
"PER": "Peru", |
|
||||||
"PHL": "Philippines", |
|
||||||
"PLW": "Palau", |
|
||||||
"PNG": "Papua New Guinea", |
|
||||||
"POL": "Poland", |
|
||||||
"PRI": "Puerto Rico", |
|
||||||
"PRK": "Korea, Democratic People's Republic of", |
|
||||||
"PRT": "Portugal", |
|
||||||
"PRY": "Paraguay", |
|
||||||
"PSE": "Palestine, State of", |
|
||||||
"PYF": "French Polynesia", |
|
||||||
"QAT": "Qatar", |
|
||||||
"REU": "RĂ©union", |
|
||||||
"ROU": "Romania", |
|
||||||
"RUS": "Russian Federation", |
|
||||||
"RWA": "Rwanda", |
|
||||||
"SAU": "Saudi Arabia", |
|
||||||
"SDN": "Sudan", |
|
||||||
"SEN": "Senegal", |
|
||||||
"SGP": "Singapore", |
|
||||||
"SGS": "South Georgia and the South Sandwich Islands", |
|
||||||
"SHN": "Saint Helena, Ascension and Tristan da Cunha", |
|
||||||
"SJM": "Svalbard and Jan Mayen", |
|
||||||
"SLB": "Solomon Islands", |
|
||||||
"SLE": "Sierra Leone", |
|
||||||
"SLV": "El Salvador", |
|
||||||
"SMR": "San Marino", |
|
||||||
"SOM": "Somalia", |
|
||||||
"SPM": "Saint Pierre and Miquelon", |
|
||||||
"SRB": "Serbia", |
|
||||||
"SSD": "South Sudan", |
|
||||||
"STP": "Sao Tome and Principe", |
|
||||||
"SUR": "Suriname", |
|
||||||
"SVK": "Slovakia", |
|
||||||
"SVN": "Slovenia", |
|
||||||
"SWE": "Sweden", |
|
||||||
"SWZ": "Swaziland", |
|
||||||
"SXM": "Sint Maarten (Dutch part)", |
|
||||||
"SYC": "Seychelles", |
|
||||||
"SYR": "Syrian Arab Republic", |
|
||||||
"TCA": "Turks and Caicos Islands", |
|
||||||
"TCD": "Chad", |
|
||||||
"TGO": "Togo", |
|
||||||
"THA": "Thailand", |
|
||||||
"TJK": "Tajikistan", |
|
||||||
"TKL": "Tokelau", |
|
||||||
"TKM": "Turkmenistan", |
|
||||||
"TLS": "Timor-Leste", |
|
||||||
"TON": "Tonga", |
|
||||||
"TTO": "Trinidad and Tobago", |
|
||||||
"TUN": "Tunisia", |
|
||||||
"TUR": "Turkey", |
|
||||||
"TUV": "Tuvalu", |
|
||||||
"TWN": "Taiwan, Province of China", |
|
||||||
"TZA": "Tanzania, United Republic of", |
|
||||||
"UGA": "Uganda", |
|
||||||
"UKR": "Ukraine", |
|
||||||
"UMI": "United States Minor Outlying Islands", |
|
||||||
"URY": "Uruguay", |
|
||||||
"USA": "United States", |
|
||||||
"UZB": "Uzbekistan", |
|
||||||
"VAT": "Holy See (Vatican City State)", |
|
||||||
"VCT": "Saint Vincent and the Grenadines", |
|
||||||
"VEN": "Venezuela, Bolivarian Republic of", |
|
||||||
"VGB": "Virgin Islands, British", |
|
||||||
"VIR": "Virgin Islands, U.S.", |
|
||||||
"VNM": "Viet Nam", |
|
||||||
"VUT": "Vanuatu", |
|
||||||
"WLF": "Wallis and Futuna", |
|
||||||
"WSM": "Samoa", |
|
||||||
"YEM": "Yemen", |
|
||||||
"ZAF": "South Africa", |
|
||||||
"ZMB": "Zambia", |
|
||||||
"ZWE": "Zimbabwe" |
|
||||||
} |
|
@ -1,13 +0,0 @@ |
|||||||
|
|
||||||
function setup(){ |
|
||||||
return query; |
|
||||||
} |
|
||||||
|
|
||||||
function query( clean ){ |
|
||||||
return { |
|
||||||
type: 'mock', |
|
||||||
body: clean |
|
||||||
}; |
|
||||||
} |
|
||||||
|
|
||||||
module.exports = setup; |
|
@ -1,40 +0,0 @@ |
|||||||
var proxyquire = require('proxyquire'); |
|
||||||
|
|
||||||
var stubConfig = { |
|
||||||
generate: function generate() { |
|
||||||
return { |
|
||||||
esclient: { |
|
||||||
hosts: [ |
|
||||||
'http://notLocalhost:9200', |
|
||||||
'http://anotherHost:9200' |
|
||||||
] |
|
||||||
} |
|
||||||
}; |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
|
|
||||||
module.exports.tests = {}; |
|
||||||
|
|
||||||
module.exports.tests.config_properly_passed = function(test, common) { |
|
||||||
test('Elasticsearch config is properly passed to elasticsearch module', function(t) { |
|
||||||
var stubElasticsearchClient = { |
|
||||||
Client: function(config) { |
|
||||||
t.deepEquals(config.hosts, [ 'http://notLocalhost:9200', 'http://anotherHost:9200' ], 'hosts set correctly' ); |
|
||||||
t.end(); |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
proxyquire('../../../src/backend', { 'pelias-config': stubConfig, 'elasticsearch': stubElasticsearchClient } ); |
|
||||||
}); |
|
||||||
}; |
|
||||||
|
|
||||||
module.exports.all = function (tape, common) { |
|
||||||
function test(name, testFunction) { |
|
||||||
return tape('SANTIZE src/backend ' + name, testFunction); |
|
||||||
} |
|
||||||
|
|
||||||
for( var testCase in module.exports.tests ){ |
|
||||||
module.exports.tests[testCase](test, common); |
|
||||||
} |
|
||||||
}; |
|
Loading…
Reference in new issue