Skip to content

Commit

Permalink
21134 - Updated business lookup (bcgov#2855)
Browse files Browse the repository at this point in the history
* - app version = 2.6.25
- added safe fallback in case FF is not returned / null in Business Lookup component
- removed legalType fallback in Business Lookup Service
- updated unit test

* - used built-in FF fallback

---------

Co-authored-by: Severin Beauvais <[email protected]>
Co-authored-by: Travis Semple <[email protected]>
  • Loading branch information
3 people authored Jun 6, 2024
1 parent 9936065 commit 5b741ad
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions auth-web/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 auth-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auth-web",
"version": "2.6.26",
"version": "2.6.27",
"appName": "Auth Web",
"sbcName": "SBC Common Components",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,13 @@ export default defineComponent({
if (!states.searchField || states.searchField?.length <= 2) {
return
}
states.state = States.SEARCHING
const searchStatus = null // search all (ACTIVE + HISTORICAL)
const legalType = launchdarklyServices.getFlag(LDFlags.AllowableBusinessSearchTypes)
// fetch list of legal types from LaunchDarkly
// if not available, fall back to same value as Prod
const legalType = launchdarklyServices.getFlag(LDFlags.AllowableBusinessSearchTypes, 'BEN,SP,GP,CP')
// Use appropriate service based on lookupType
const searchService = (props.lookupType === LookupType.NR)
? NameRequestLookupServices.search
Expand Down
2 changes: 1 addition & 1 deletion auth-web/src/services/business-lookup.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export default class BusinessLookupServices {
/**
* Searches for business by code or words.
* @param query code or words to search
* @param legalType the comma-separated list of legal types to match
* @param status status to match (ACTIVE or HISTORICAL or empty to match all statuses)
* @returns a promise to return the search results
*/
static async search (query: string, legalType: string, status = ''): Promise<BusinessLookupResultIF[]> {
legalType ||= 'A,BC,BEN,C,CC,CP,CUL,FI,GP,LL,LLC,LP,PA,S,SP,ULC,XCP,XL,XP,XS'
let url = this.registriesSearchApiUrl + 'businesses/search/facets?start=0&rows=20'
url += `&categories=legalType:${legalType}${status ? '::status:' + status : ''}`
url += `&query=value:${encodeURIComponent(query)}`
Expand Down
10 changes: 4 additions & 6 deletions auth-web/tests/unit/services/business-lookup.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ describe('Business Lookup Services', () => {
}

const url = BusinessLookupServices.registriesSearchApiUrl + 'businesses/search/facets?start=0&rows=20' +
'&categories=legalType:A,BC,BEN,C,CC,CP,CUL,FI,GP,LL,LLC,LP,PA,S,SP,ULC,XCP,XL,XP,XS' +
`&query=value:${encodeURIComponent('FM1000002')}`
`&categories=legalType:SP&query=value:${encodeURIComponent('FM1000002')}`

sinon.stub(axios, 'get').withArgs(url).returns(
Promise.resolve({ data: { searchResults: { results: [result] } } })
)

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

Expand All @@ -32,14 +31,13 @@ describe('Business Lookup Services', () => {
it('does not return a result when the business is not found', async () => {
// mock unsuccesssful search
const url = BusinessLookupServices.registriesSearchApiUrl + 'businesses/search/facets?start=0&rows=20' +
'&categories=legalType:A,BC,BEN,C,CC,CP,CUL,FI,GP,LL,LLC,LP,PA,S,SP,ULC,XCP,XL,XP,XS' +
`&query=value:${encodeURIComponent('FM1000003')}`
`&categories=legalType:SP&query=value:${encodeURIComponent('FM1000003')}`

sinon.stub(axios, 'get').withArgs(url).returns(
Promise.resolve({ data: { searchResults: { results: [] } } })
)

const results = await BusinessLookupServices.search('FM1000003')
const results = await BusinessLookupServices.search('FM1000003', 'SP')
expect(results.length).toBe(0)

sinon.restore()
Expand Down

0 comments on commit 5b741ad

Please sign in to comment.