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

17158 update fetchNameRequest #540

Merged
merged 8 commits into from
Nov 14, 2023
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
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.7.6",
"version": "4.7.7",
"private": true,
"appName": "Edit UI",
"sbcName": "SBC Common Components",
Expand Down
4 changes: 2 additions & 2 deletions src/dialogs/NameRequestErrorDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

<p
v-else-if="type === NameRequestStates.NOT_FOUND ||
type === NameRequestStates.INCORRECT_EMAIL ||
type === NameRequestStates.INCORRECT_PHONE"
type === NameRequestStates.INCORRECT_CONTACT ||
type === NameRequestStates.NO_CONTACT"
>
We could not find a match for the information you have entered.
Please verify the NR Number and the phone number or email address and try again.
Expand Down
6 changes: 2 additions & 4 deletions src/enums/nameRequestStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ export enum NameRequestStates {
INPROGRESS = 'INPROGRESS',
REJECTED = 'REJECTED',
NRO_UPDATING = 'NRO_UPDATING',
NO_CONTACT = 'NO_CONTACT',
INCORRECT_CONTACT = 'INCORRECT_CONTACT',
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved

// ADDITIONAL UI STATES FOR ERROR HANDLING
NOT_APPROVED = 'NOT_APPROVED',
CONSUMED = 'CONSUMED',
NOT_FOUND = 'NOT_FOUND',
NEED_CONSENT = 'NEED_CONSENT',
INVALID = 'INVALID',

// ADDITIONAL UI STATES FOR NR VALIDATION
INCORRECT_EMAIL = 'INCORRECT_EMAIL',
INCORRECT_PHONE = 'INCORRECT_PHONE',
}
26 changes: 12 additions & 14 deletions src/mixins/name-request-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NrRequestActionCodes } from '@bcrs-shared-components/enums'
import { LegalServices } from '@/services/'
import { NrResponseIF, ResourceIF } from '@/interfaces/'
import { useStore } from '@/store/store'
import { StatusCodes } from 'http-status-codes'

/**
* Mixin for processing Name Request objects.
Expand All @@ -23,23 +24,20 @@ export default class NameRequestMixin extends Vue {
* @returns the name request response payload
*/
async validateNameRequest (nrNumber: string, phone?: string, email?: string): Promise<NrResponseIF> {
const nrResponse: NrResponseIF = await LegalServices.fetchNameRequest(nrNumber).catch(error => {
this.$root.$emit('invalid-name-request', NameRequestStates.NOT_FOUND)
const nrResponse: NrResponseIF = await LegalServices.fetchNameRequest(nrNumber, phone, email).catch(error => {
if (error?.response?.status === StatusCodes.NOT_FOUND) {
this.$root.$emit('invalid-name-request', NameRequestStates.NOT_FOUND)
throw new Error(`${nrNumber} not found`) // Sent invalid NR number
} else if (error?.response?.status === StatusCodes.BAD_REQUEST) {
this.$root.$emit('invalid-name-request', NameRequestStates.INCORRECT_CONTACT)
throw new Error('Sent invalid email or phone number.') // Sent invalid email or phone
} else if (error?.response?.status === StatusCodes.FORBIDDEN) {
this.$root.$emit('invalid-name-request', NameRequestStates.NO_CONTACT)
throw new Error('Not sent email or phone number.') // Not sent the email or phone
}
throw new Error(`Fetch Name Request error: ${error}`)
})
severinbeauvais marked this conversation as resolved.
Show resolved Hide resolved

// validate email
if (email && nrResponse.applicants?.emailAddress !== email) {
this.$root.$emit('invalid-name-request', NameRequestStates.INCORRECT_EMAIL)
throw new Error(`Incorrect Email`)
}

// validate phone
if (phone && nrResponse.applicants?.phoneNumber !== phone) {
this.$root.$emit('invalid-name-request', NameRequestStates.INCORRECT_PHONE)
throw new Error(`Incorrect Phone`)
}

// ensure NR is valid
const isNrValid = this.isNrValid(nrResponse)
if (!nrResponse || !isNrValid) {
Expand Down
6 changes: 4 additions & 2 deletions src/services/legal-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,12 @@ export default class LegalServices {
/**
* Fetches name request data.
* @param nrNumber the name request number (eg, NR 1234567) to fetch
* @param phone the name request phone (eg, 12321232)
* @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 fetchNameRequest (nrNumber: string): Promise<any> {
const url = `nameRequests/${nrNumber}`
static async fetchNameRequest (nrNumber: string, phone = '', email = ''): Promise<any> {
const url = `nameRequests/${nrNumber}/validate?phone=${phone}&email=${email}`

return axios.get(url)
.then(response => {
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 @@ -236,7 +236,7 @@ describe.skip('Emits error event if NR validation fails in file and pay', () =>
expiredNR['expirationDate'] = 'Thu, 31 Dec 2019 23:59:59 GMT'

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

// GET NR data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(Promise.resolve({
data:
{
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 @@ -439,7 +439,7 @@ describe.skip('App component', () => {
}))

// GET NR data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(Promise.resolve({
data:
{
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/CorrectNameRequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe('CorrectNameRequest', () => {
store.stateModel.tombstone.currentDate = '2021-01-20'

// GET NR Data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=250 516 8257&email=')
.returns(Promise.resolve({
data:
{
Expand Down Expand Up @@ -338,7 +338,7 @@ describe('CorrectNameRequest', () => {
const vm = wrapper.vm as any

// GET NR Data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=250 516 8258&email=mock@example.com')
.returns(Promise.resolve({
data:
{
Expand Down Expand Up @@ -383,7 +383,7 @@ describe('CorrectNameRequest', () => {
const vm = wrapper.vm as any

// GET NR Data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=250 516 8258&email=mock@example.com')
.returns(Promise.resolve({
data:
{
Expand Down Expand Up @@ -430,7 +430,7 @@ describe('CorrectNameRequest', () => {
store.stateModel.tombstone.currentDate = '2021-01-20'

// GET NR Data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=250 516 8257&email=')
.returns(Promise.resolve({
data:
{
Expand Down Expand Up @@ -483,7 +483,7 @@ describe('CorrectNameRequest', () => {
store.stateModel.tombstone.entityType = CorpTypeCd.PARTNERSHIP

// GET NR Data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=250 516 8257&email=')
.returns(Promise.resolve({
data:
{
Expand Down Expand Up @@ -531,7 +531,7 @@ describe('CorrectNameRequest', () => {
store.stateModel.tombstone.entityType = CorpTypeCd.SOLE_PROP

// GET NR Data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=250 516 8258&email=')
.returns(Promise.resolve({
data:
{
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/NameRequestErrorDialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Name Request Error Dialog', () => {
it('displays "incorrect email" message', async () => {
const wrapper = mount(NameRequestErrorDialog, {
vuetify,
propsData: { dialog: true, type: 'INCORRECT_EMAIL' }
propsData: { dialog: true, type: 'INCORRECT_CONTACT' }
})
await Vue.nextTick()

Expand All @@ -48,7 +48,7 @@ describe('Name Request Error Dialog', () => {
it('displays "incorrect phone" message', async () => {
const wrapper = mount(NameRequestErrorDialog, {
vuetify,
propsData: { dialog: true, type: 'INCORRECT_PHONE' }
propsData: { dialog: true, type: 'NO_CONTACT' }
})
await Vue.nextTick()

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/legal-services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('Legal Services', () => {
}

// mock endpoint
get.withArgs('nameRequests/NR1234567')
get.withArgs('nameRequests/NR1234567/validate?phone=&email=')
.returns(Promise.resolve({ data: NR }))

// call method
Expand Down Expand Up @@ -332,7 +332,7 @@ describe('Legal Services', () => {
await expect(LegalServices.fetchResolutions('CP1234567')).rejects.toThrow('Invalid API response')

// verify fetchNameRequest with no response.data
get.withArgs('nameRequests/NR1234567').returns(Promise.resolve({}))
get.withArgs('nameRequests/NR1234567/validate?phone=&email=').returns(Promise.resolve({}))
await expect(LegalServices.fetchNameRequest('NR1234567')).rejects.toThrow('Invalid API response')

// verify fetchBusinessDocuments with no response.data
Expand Down
44 changes: 5 additions & 39 deletions tests/unit/name-request-mixin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Name Request Mixin', () => {
console.log = vi.fn()

// mock fetchNameRequest to throw an error
get.withArgs('nameRequests/NR 1234567').returns(Promise.resolve(null))
get.withArgs('nameRequests/NR 1234567/validate?phone=phone&email=email').returns(Promise.resolve(null))

try {
await vm.validateNameRequest('NR 1234567', 'phone', 'email')
Expand All @@ -65,43 +65,9 @@ describe('Name Request Mixin', () => {
console.log = log
})

it('handles incorrect email errors', async () => {
// mock fetchNameRequest to return different email address
get.withArgs('nameRequests/NR 1234567')
.returns(Promise.resolve({ data: {
applicants: { emailAddress: 'other' }
} }))

try {
await vm.validateNameRequest('NR 1234567', 'phone', 'email')
} catch (err) {
// verify thrown error
expect((err as any).message).toBe('Incorrect Email')
// FUTURE: figure out how to verify emitted error (invalid-name-request)
// expect(wrapper.emitted('invalid-name-request')).toEqual([['INCORRECT_EMAIL']])
}
})

it('handles incorrect phone errors', async () => {
// mock fetchNameRequest to return different phone number
get.withArgs('nameRequests/NR 1234567')
.returns(Promise.resolve({ data: {
applicants: { emailAddress: 'email', phoneNumber: 'other' }
} }))

try {
await vm.validateNameRequest('NR 1234567', 'phone', 'email')
} catch (err) {
// verify thrown error
expect((err as any).message).toBe('Incorrect Phone')
// FUTURE: figure out how to verify emitted error (invalid-name-request)
// expect(wrapper.emitted('invalid-name-request')).toEqual([['INCORRECT_PHONE']])
}
})

it('handles invalid name requests', async () => {
// mock fetchNameRequest to return invalid NR
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=phone&email=email')
.returns(Promise.resolve({ data: {
applicants: { emailAddress: 'email', phoneNumber: 'phone' }
} }))
Expand All @@ -118,7 +84,7 @@ describe('Name Request Mixin', () => {

it('handles invalid name request states', async () => {
// mock fetchNameRequest to return invalid NR state
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=phone&email=email')
.returns(Promise.resolve({ data: {
applicants: { emailAddress: 'email', phoneNumber: 'phone' },
state: 'DRAFT',
Expand All @@ -141,7 +107,7 @@ describe('Name Request Mixin', () => {

it('handles conditional state with consent required', async () => {
// mock fetchNameRequest to return invalid NR state
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=phone&email=email')
.returns(Promise.resolve({ data: {
applicants: { emailAddress: 'email', phoneNumber: 'phone' },
state: 'CONDITIONAL',
Expand All @@ -165,7 +131,7 @@ describe('Name Request Mixin', () => {

it('handles conditional state with consent received', async () => {
// mock fetchNameRequest to return valid NR state
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=phone&email=email')
.returns(Promise.resolve({ data: {
applicants: { emailAddress: 'email', phoneNumber: 'phone' },
state: 'CONDITIONAL',
Expand Down
Loading