Skip to content

Commit

Permalink
replace fetch NR func
Browse files Browse the repository at this point in the history
  • Loading branch information
kzdev420 committed Oct 26, 2023
1 parent 2a0a582 commit 15d9700
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 12 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-create-ui",
"version": "5.5.7",
"version": "5.5.8",
"private": true,
"appName": "Create UI",
"sbcName": "SBC Common Components",
Expand Down
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ export default class App extends Mixins(CommonMixin, DateMixin, FilingTemplateMi
const nrNumber = filing[filing.header?.name].nameRequest.nrNumber
// fetch NR data
const nrResponse = await LegalServices.fetchNameRequest(nrNumber).catch(error => {
const nrResponse = await LegalServices.fetchValidContactNr(nrNumber).catch(error => {
console.log('NR error =', error) // eslint-disable-line no-console
this.nameRequestInvalidErrorDialog = true
})
Expand Down
3 changes: 2 additions & 1 deletion src/components/Restoration/BusinessName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ export default class BusinessName extends Mixins(CommonMixin, DateMixin, NameReq
const nameRequest = await LegalServices.fetchValidContactNr(nrNum, phone, email)
if (!nameRequest) throw new Error('Error fetching Name Request')
return nameRequest
// validateNameRequest() already throws printable errors
return this.validateNameRequest(nameRequest, this.requestActionCode)
}
/** On company name update, sets store accordingly. */
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/Actions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export default class Actions extends Mixins(CommonMixin, DateMixin, FilingTempla
// FUTURE: merge this with NameRequestMixin::validateNameRequest()
/** Fetches NR and validates it. */
private async _validateNameRequest (nrNumber: string): Promise<void> {
const nameRequest = await LegalServices.fetchNameRequest(nrNumber).catch(error => {
const nameRequest = await LegalServices.fetchValidContactNr(nrNumber).catch(error => {
this.$root.$emit('name-request-retrieve-error')
throw new Error(error)
})
Expand Down
8 changes: 6 additions & 2 deletions src/services/legal-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ export default class LegalServices {
* Fetches name request data with phone and email validation.
* @param nrNumber the name request number (eg, NR 1234567)
* @param phone the name request phone (eg, 12321232)
* @param email the name request email (eg, ab@gmail.com)
* @param email the name request email (eg, nr@example.com)
* @returns a promise to return the NR data, or null if not found
*/
static async fetchValidContactNr (nrNumber: string, phone?: string, email?: string): Promise<NameRequestIF> {
static async fetchValidContactNr (nrNumber: string, phone = '', email = ''): Promise<NameRequestIF> {
if (!nrNumber) throw new Error('Invalid parameter \'nrNumber\'')

const url = `nameRequests/${nrNumber}/validate?phone=${phone}&email=${email}`
Expand All @@ -152,6 +152,10 @@ export default class LegalServices {
}).catch(error => {
if (error?.response?.status === StatusCodes.NOT_FOUND) {
return null // NR not found (not an error)
} else if (error?.response?.status === StatusCodes.BAD_REQUEST) {
throw new Error('Sent invalid email or phone number.') // Sent invalid email or phone
} else if (error?.response?.status === StatusCodes.FORBIDDEN) {
throw new Error('Not sent email or phone number.') // Not sent the email or phone
}
throw error
})
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('Emits error event if NR validation fails in file and pay', () => {

// GET NR data
sinon.stub(axios, 'get')
.withArgs('nameRequests/NR 1234567')
.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(new Promise(resolve => resolve({
data: expiredNR
})))
Expand Down Expand Up @@ -378,7 +378,7 @@ describe('Actions component - Filing Functionality', () => {

// GET NR data
sinon.stub(axios, 'get')
.withArgs('nameRequests/NR 1234567')
.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(new Promise(resolve => resolve({
data: { ...nrData }
})))
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/App.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ describe('Incorporation - Define Company page for a BEN (named)', () => {
})))

// GET NR data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(new Promise(resolve => resolve({
data:
{
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/BusinessName.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ setActivePinia(createPinia())
const store = useStore()

// mock services function
const mockFetchNameRequest = vi.spyOn((LegalServices as any), 'updateFiling').mockImplementation()
const mockFetchValidContactNr = vi.spyOn((LegalServices as any), 'updateFiling').mockImplementation()

describe('Business Name component', () => {
let wrapper: any
Expand Down

0 comments on commit 15d9700

Please sign in to comment.