Skip to content

Commit

Permalink
add api.locator endpoint and tests (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandiest committed Nov 9, 2016
1 parent 5af975f commit 8f3d653
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}
}
Expand Down Expand Up @@ -319,5 +323,10 @@ const validators = {
if(isEmptyObject(query)) {
throw new InvalidArgumentError('query')
}
},
locator_query(query) {
if(isEmptyObject(query)) {
throw new InvalidArgumentError('query')
}
}
}
3 changes: 3 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@ export const ApiPaths = {
},
search: (scope) => {
return `/forte/search/${scope.trunk}/${scope.branch}/`
},
locator: (scope) => {
return `/forte/locator/${scope.trunk}`
}
}
35 changes: 35 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8f3d653

Please sign in to comment.