diff --git a/src/index.js b/src/index.js index d734720..8573a06 100644 --- a/src/index.js +++ b/src/index.js @@ -163,9 +163,9 @@ function forteApi(credentials, scope, options) { } } }, - search(query) { + search(query, params) { validateArgs('search_query', arguments) - return client.post(ApiPaths.search(scope), { data: query }) + return client.post(ApiPaths.search(scope), { params, data: query }) } } } diff --git a/src/util.js b/src/util.js index 69eb895..cf4d337 100644 --- a/src/util.js +++ b/src/util.js @@ -57,7 +57,7 @@ export const ApiPaths = { carts: scope => { return `/forte/organizations/${scope.trunk}/${scope.branch}/carts` }, - search: scope => { + search: (scope) => { return `/forte/search/${scope.trunk}/${scope.branch}/` } } diff --git a/test/index.js b/test/index.js index 9bdd709..ea066b1 100644 --- a/test/index.js +++ b/test/index.js @@ -620,14 +620,35 @@ describe('forteApi', () => { }) }) - const validQueries = [{bool: true}] + const validQueries = [{query: {bool: true}}] validQueries.forEach((query) => { const expected = expectedUri(ApiPaths.search(validTrunkAndBranchScope)) it(`should POST uri: ${expected}`, () => { - const getSearchMock = mockapi.post(expected, 200, query) - return api.search(query).then(() => { + const getSearchMock = mockapi.post(expected, 200) + + return api.search(query.query).then(() => { + getSearchMock.done() + }) + }) + }) + }) + + describe('api.seach(query, params)', () => { + const validQueries = [ + { params: undefined, query: { bool: true }}, + { params: { types: 'x,y'}, query: { bool: true }}, + { params: { types: 'x,y', from: 1, size: 10 }, query: { bool: true }} + ] + + validQueries.forEach((query) => { + const expected = expectedUri(ApiPaths.search(validTrunkAndBranchScope), query.params) + + it(`should POST uri: ${expected}`, () => { + const getSearchMock = mockapi.post(expected, 200) + + return api.search(query.query, query.params).then(() => { getSearchMock.done() }) }) @@ -637,5 +658,5 @@ describe('forteApi', () => { // only used for assert output, not actual test function expectedUri(path, query) { - return path + (query ? '?' + stringify(query) : '') + return path + (query && query ? '?' + stringify(query) : '') }