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

17159 Update fetchNameRequest #579

Merged
merged 1 commit 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-filings-ui",
"version": "7.0.8",
"version": "7.0.9",
"private": true,
"appName": "Filings UI",
"sbcName": "SBC Common Components",
Expand Down
33 changes: 26 additions & 7 deletions src/services/legal-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { AxiosResponse } from 'axios'
import { ApiBusinessIF, ApiFilingIF, CommentIF, DocumentIF, FetchDocumentsIF, NameRequestIF,
PresignedUrlIF } from '@/interfaces'
import { DigitalCredentialTypes, FilingStatus, Roles } from '@/enums'
import { StatusCodes } from 'http-status-codes'

/**
* Class that provides integration with the Legal API.
Expand Down Expand Up @@ -95,15 +96,33 @@ export default class LegalServices {
}

/**
* Fetches a Name Request.
* @param filingId the NR number
* @returns the name request object
* 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<NameRequestIF> {
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)
// workaround because data is at "response.data.data"
.then(response => response?.data)
.then(response => {
if (response?.data) {
return response.data
}
// eslint-disable-next-line no-console
console.log('fetchNameRequest() error - invalid response =', response)
throw new Error('Invalid API response')
}).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
16 changes: 8 additions & 8 deletions tests/unit/App.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ describe('App as a Draft IA with approved NR', () => {
})))

// GET NR data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(new Promise(resolve => resolve({
data: {
applicants: {},
Expand Down Expand Up @@ -1032,7 +1032,7 @@ describe('App as a Draft IA with conditional-not required NR', () => {
})))

// GET NR data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(new Promise(resolve => resolve({
data: {
applicants: {},
Expand Down Expand Up @@ -1135,7 +1135,7 @@ describe('App as a Draft IA with conditional-received NR', () => {
})))

// GET NR data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(new Promise(resolve => resolve({
data: {
applicants: {},
Expand Down Expand Up @@ -1238,7 +1238,7 @@ describe('App as a Draft IA with conditional-waived NR', () => {
})))

// GET NR data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(new Promise(resolve => resolve({
data: {
applicants: {},
Expand Down Expand Up @@ -1341,7 +1341,7 @@ describe('App as a PAID (pending) Incorporation Application', () => {
})))

// GET NR data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(new Promise(resolve => resolve({
data: {
applicants: {},
Expand Down Expand Up @@ -1488,7 +1488,7 @@ describe('App as a COMPLETED Incorporation Application', () => {
})))

// GET NR data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(new Promise(resolve => resolve({
data: {
applicants: {},
Expand Down Expand Up @@ -1769,7 +1769,7 @@ describe('App as a Draft Registration with approved NR', () => {
})))

// GET NR data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(new Promise(resolve => resolve({
data: {
applicants: {},
Expand Down Expand Up @@ -1892,7 +1892,7 @@ describe('App as a COMPLETED Registration Application', () => {
})))

// GET NR data
get.withArgs('nameRequests/NR 1234567')
get.withArgs('nameRequests/NR 1234567/validate?phone=&email=')
.returns(new Promise(resolve => resolve({
data: {
applicants: {},
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/legal-services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('Legal Services', () => {
}

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

// call method
Expand Down
Loading