Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17160 Update fetchNr with phone and email validation #578

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
576 changes: 334 additions & 242 deletions package-lock.json

Large diffs are not rendered by default.

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
4 changes: 2 additions & 2 deletions src/components/Restoration/BusinessName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ export default class BusinessName extends Mixins(CommonMixin, DateMixin, NameReq
* @returns a promise to return the NR, or throws a printable error
*/
async fetchAndValidateNr (nrNum: string, phone: string, email: string): Promise<NameRequestIF> {
const nameRequest = await LegalServices.fetchNameRequest(nrNum)
const nameRequest = await LegalServices.fetchValidContactNr(nrNum, phone, email)
if (!nameRequest) throw new Error('Error fetching Name Request')
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved

// validateNameRequest() already throws printable errors
return this.validateNameRequest(nameRequest, this.requestActionCode, phone, email)
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
return this.validateNameRequest(nameRequest, this.requestActionCode)
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved
}

/** 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
12 changes: 9 additions & 3 deletions src/services/legal-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,16 @@ export default class LegalServices {
}

/**
* Fetches name request data.
* 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, [email protected])
* @returns a promise to return the NR data, or null if not found
*/
static async fetchNameRequest (nrNumber: string): Promise<NameRequestIF> {
static async fetchValidContactNr (nrNumber: string, phone = '', email = ''): Promise<NameRequestIF> {
if (!nrNumber) throw new Error('Invalid parameter \'nrNumber\'')

const url = `nameRequests/${nrNumber}`
const url = `nameRequests/${nrNumber}/validate?phone=${phone}&email=${email}`
return axios.get(url)
.then(response => {
const data = response?.data
Expand All @@ -128,6 +130,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
Loading