Skip to content

Commit

Permalink
feat: amend search api (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandiest authored Sep 26, 2016
1 parent 22c849a commit beb1f01
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}/`
}
}
29 changes: 25 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand All @@ -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) : '')
}

0 comments on commit beb1f01

Please sign in to comment.