From 8f3d653c364686f1452aa2bb6cdf3e74ce17db65 Mon Sep 17 00:00:00 2001 From: Michael Van Diest Date: Wed, 9 Nov 2016 14:54:55 -0500 Subject: [PATCH] add api.locator endpoint and tests (#7) --- src/index.js | 9 +++++++++ src/util.js | 3 +++ test/index.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/index.js b/src/index.js index acc0db9..30850af 100644 --- a/src/index.js +++ b/src/index.js @@ -166,6 +166,10 @@ function forteApi(credentials, scope, options) { search(query, params) { validateArgs('search_query', arguments) return client.post(ApiPaths.search(scope), { params, data: query }) + }, + locator(query) { + validateArgs('locator_query', arguments) + return client.post(ApiPaths.locator(scope), { data: query }) } } } @@ -319,5 +323,10 @@ const validators = { if(isEmptyObject(query)) { throw new InvalidArgumentError('query') } + }, + locator_query(query) { + if(isEmptyObject(query)) { + throw new InvalidArgumentError('query') + } } } diff --git a/src/util.js b/src/util.js index cf4d337..2568af6 100644 --- a/src/util.js +++ b/src/util.js @@ -59,5 +59,8 @@ export const ApiPaths = { }, search: (scope) => { return `/forte/search/${scope.trunk}/${scope.branch}/` + }, + locator: (scope) => { + return `/forte/locator/${scope.trunk}` } } diff --git a/test/index.js b/test/index.js index 350def5..02708c7 100644 --- a/test/index.js +++ b/test/index.js @@ -675,6 +675,41 @@ describe('forteApi', () => { }) }) }) + + describe('api.locator(query)', () => { + const invalidQueries = [null, undefined, {}, '', () => {}] + invalidQueries.forEach((query) => { + it(`should throw for query '${JSON.stringify(query)}'`, () => { + assert.throws(() => { api.search(query) }, InvalidArgumentError) + }) + }) + + const validQueries = [ + { + city: 'Saint Petersburg', + stateProvince: 'FL', + countToReturn: 100, + radius: 100 + }, + { + postalCode: '33701', + countToReturn: 5, + radius: 100 + } + ] + + validQueries.forEach((query) => { + const expected = expectedUri(ApiPaths.locator(validTrunkAndBranchScope)) + + it(`should POST uri: ${expected}`, () => { + const getLocatorMock = mockapi.post(expected, 200) + + return api.locator(query).then(() => { + getLocatorMock.done() + }) + }) + }) + }) }) // only used for assert output, not actual test