Skip to content

Commit

Permalink
- app version = 4.9.2 (bcgov#574)
Browse files Browse the repository at this point in the history
- refactored BusinessLookupServices.search() to use legalTypes parameter (same as in Create UI)
- updated unit tests

Co-authored-by: Severin Beauvais <[email protected]>
  • Loading branch information
severinbeauvais and Severin Beauvais authored Jun 11, 2024
1 parent 31f470e commit 2de7847
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "business-edit-ui",
"version": "4.9.1",
"version": "4.9.2",
"private": true,
"appName": "Edit UI",
"sbcName": "SBC Common Components",
Expand Down
13 changes: 7 additions & 6 deletions src/services/business-lookup-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ export default class BusinessLookupServices {
* Searches for business by code or words.
* @param query code or words to search
* @param status status to match (ACTIVE or HISTORICAL or '' to match all statuses)
* @param legalTypes - the legal types we're searching for
* @returns a promise to return the search results
*/
static async search (query: string, status: string): Promise<BusinessLookupResultIF[]> {
const legalType = 'BC,A,ULC,C,S,XP,GP,LP,CUL,XS,LLC,LL,BEN,CP,CC,XL,FI,XCP,PA'

static async search (query: string, status: string, legalTypes: string): Promise<BusinessLookupResultIF[]> {
let url = this.searchApiUrl + 'businesses/search/facets?start=0&rows=20'
url += `&categories=legalType:${legalType}${status ? '::status:' + status : ''}`
url += `&categories=legalType:${legalTypes}${status ? '::status:' + status : ''}`
url += `&query=value:${encodeURIComponent(query)}`

return axios.get(url, {
const config = {
headers: {
'x-apikey': this.searchApiKey,
'Account-Id': this.accountId
}
}).then(response => {
}

return axios.get(url, config).then(response => {
const results: Array<BusinessLookupResultIF> = response?.data?.searchResults?.results
if (!results) {
throw new Error('Invalid API response')
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/business-lookup-services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ describe('Business Lookup Services', () => {
// mock successsful search
sinon.stub(axios, 'get')
.withArgs('https://search.api.url/businesses/search/facets?start=0&rows=20&categories=legalType:' +
'BC,A,ULC,C,S,XP,GP,LP,CUL,XS,LLC,LL,BEN,CP,CC,XL,FI,XCP,PA::status:ACTIVE&query=value:FM1000002')
'SP::status:ACTIVE&query=value:FM1000002')
.returns(new Promise(resolve => resolve({ data: { searchResults: { results: [result] } } })))

// search and look at results
const results = await BusinessLookupServices.search('FM1000002', 'ACTIVE')
const results = await BusinessLookupServices.search('FM1000002', 'ACTIVE', 'SP')
expect(results.length).toBe(1)
expect(results[0]).toEqual(result)

Expand All @@ -35,11 +35,11 @@ describe('Business Lookup Services', () => {
// mock unsuccesssful search
sinon.stub(axios, 'get')
.withArgs('https://search.api.url/businesses/search/facets?start=0&rows=20&categories=legalType' +
':BC,A,ULC,C,S,XP,GP,LP,CUL,XS,LLC,LL,BEN,CP,CC,XL,FI,XCP,PA::status:ACTIVE&query=value:FM1000003')
':SP::status:ACTIVE&query=value:FM1000003')
.returns(new Promise(resolve => resolve({ data: { searchResults: { results: [] } } })))

// search and look at results
const results = await BusinessLookupServices.search('FM1000003', 'ACTIVE')
const results = await BusinessLookupServices.search('FM1000003', 'ACTIVE', 'SP')
expect(results.length).toBe(0)

sinon.restore()
Expand All @@ -65,11 +65,11 @@ describe('Business Lookup Services', () => {
// mock successsful search
sinon.stub(axios, 'get')
.withArgs('https://search.api.url/businesses/search/facets?start=0&rows=20&categories=legalType:' +
'BC,A,ULC,C,S,XP,GP,LP,CUL,XS,LLC,LL,BEN,CP,CC,XL,FI,XCP,PA&query=value:FM100000')
'GP,SP&query=value:FM100000')
.returns(new Promise(resolve => resolve({ data: { searchResults: { results: [result1, result2] } } })))

// search and look at results
const results = await BusinessLookupServices.search('FM100000', '')
const results = await BusinessLookupServices.search('FM100000', '', 'GP,SP')
expect(results.length).toBe(2)
expect(results[0]).toEqual(result1)
expect(results[1]).toEqual(result2)
Expand Down

0 comments on commit 2de7847

Please sign in to comment.