diff --git a/index.js b/index.js index ac8a0e9..d0a7401 100644 --- a/index.js +++ b/index.js @@ -19,12 +19,17 @@ function resolver(layers) { if (_.has(peliasConfig, 'imports.services.pip')) { return require('./src/remotePipResolver')(peliasConfig.imports.services.pip, layers); } else { - const datapath = peliasConfig.imports.whosonfirst.datapath; - return require('./src/localPipResolver')(datapath, layers); + return localResolver(layers); } } +function localResolver(layers) { + const datapath = peliasConfig.imports.whosonfirst.datapath; + return require('./src/localPipResolver')(datapath, layers); +} + module.exports = { create: create, - resolver: resolver + resolver: resolver, + localResolver: localResolver }; diff --git a/test/index.js b/test/index.js index fed4e31..8e64ce3 100644 --- a/test/index.js +++ b/test/index.js @@ -199,4 +199,40 @@ tape('tests for main entry point', (test) => { }); + test.test('localResolver function should return local resolver even if resolver would return a remote resolver', (t) => { + const resolver = proxyquire('../index', { + // verify the schema + './schema': 'this is the schema', + 'pelias-config': { + generate: (schema) => { + t.equals(schema, 'this is the schema'); + + return { + imports: { + adminLookup: { + enabled: true, + maxConcurrentReqs: 21 + }, + whosonfirst: { + datapath: 'this is the wof datapath' + }, + services: { + pip: { + url: 'this is the url' + } + } + } + }; + + } + }, + './src/localPipResolver': (datapath, layers) => { + t.equals(datapath, 'this is the wof datapath'); + t.deepEquals(layers, ['layer 1', 'layer 2']); + return 'this is the resolver'; + } + }).localResolver(['layer 1', 'layer 2']); + t.equal(resolver, 'this is the resolver'); + t.end(); + }); });