diff --git a/package-lock.json b/package-lock.json index 408988ff3..8454250d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "business-create-ui", - "version": "5.5.7", + "version": "5.5.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "business-create-ui", - "version": "5.5.7", + "version": "5.5.8", "dependencies": { "@babel/compat-data": "^7.21.5", "@bcrs-shared-components/approval-type": "1.0.19", diff --git a/package.json b/package.json index b910943f5..fc7a99e8a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/App.vue b/src/App.vue index 569c130d6..585bf1694 100644 --- a/src/App.vue +++ b/src/App.vue @@ -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 }) diff --git a/src/components/Restoration/BusinessName.vue b/src/components/Restoration/BusinessName.vue index 599cfb429..4c7fcb9ad 100644 --- a/src/components/Restoration/BusinessName.vue +++ b/src/components/Restoration/BusinessName.vue @@ -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. */ diff --git a/src/components/common/Actions.vue b/src/components/common/Actions.vue index b1c281aa6..1a46fc05f 100644 --- a/src/components/common/Actions.vue +++ b/src/components/common/Actions.vue @@ -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 { - 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) }) diff --git a/src/services/legal-services.ts b/src/services/legal-services.ts index b47bbea25..119213707 100644 --- a/src/services/legal-services.ts +++ b/src/services/legal-services.ts @@ -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 { + static async fetchValidContactNr (nrNumber: string, phone = '', email = ''): Promise { if (!nrNumber) throw new Error('Invalid parameter \'nrNumber\'') const url = `nameRequests/${nrNumber}/validate?phone=${phone}&email=${email}` @@ -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 }) diff --git a/tests/unit/Actions.spec.ts b/tests/unit/Actions.spec.ts index d8cd5204c..c7cb95346 100644 --- a/tests/unit/Actions.spec.ts +++ b/tests/unit/Actions.spec.ts @@ -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 }))) @@ -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 } }))) diff --git a/tests/unit/App.spec.ts b/tests/unit/App.spec.ts index 350b63d8f..97614965f 100644 --- a/tests/unit/App.spec.ts +++ b/tests/unit/App.spec.ts @@ -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: { diff --git a/tests/unit/BusinessName.spec.ts b/tests/unit/BusinessName.spec.ts index 7b99e93c3..242c5ea7f 100644 --- a/tests/unit/BusinessName.spec.ts +++ b/tests/unit/BusinessName.spec.ts @@ -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