-
Notifications
You must be signed in to change notification settings - Fork 166
LG-8582: Implementation of temp 500 error on PO search #7695
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
Changes from all commits
a255b07
192fc9c
205b2db
b56e7fe
00b65db
9aed906
304176a
58e6562
974dff6
0e69aef
b7d7715
5f3a807
1e8a4f2
c734f8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import { render } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { setupServer } from 'msw/node'; | ||
| import { rest } from 'msw'; | ||
| import type { SetupServerApi } from 'msw/node'; | ||
| import { LOCATIONS_URL } from './in-person-location-step'; | ||
| import { ADDRESS_SEARCH_URL } from './address-search'; | ||
| import InPersonContext from '../context/in-person'; | ||
| import InPersonLocationPostOfficeSearchStep from './in-person-location-post-office-search-step'; | ||
|
|
||
| const DEFAULT_RESPONSE = [ | ||
| { | ||
| address: '100 Main St E, Bronwood, Georgia, 39826', | ||
| location: { | ||
| latitude: 31.831686000000005, | ||
| longitude: -84.363768, | ||
| }, | ||
| street_address: '100 Main St E', | ||
| city: 'Bronwood', | ||
| state: 'GA', | ||
| zip_code: '39826', | ||
| }, | ||
| ]; | ||
|
|
||
| const DEFAULT_PROPS = { | ||
| toPreviousStep() {}, | ||
| onChange() {}, | ||
| value: {}, | ||
| registerField() {}, | ||
| }; | ||
|
|
||
| describe('InPersonLocationStep', () => { | ||
| context('initial API request throws an error', () => { | ||
| let server: SetupServerApi; | ||
| beforeEach(() => { | ||
| server = setupServer( | ||
| rest.post(ADDRESS_SEARCH_URL, (_req, res, ctx) => res(ctx.json(DEFAULT_RESPONSE))), | ||
| rest.post(LOCATIONS_URL, (_req, res, ctx) => res(ctx.status(500))), | ||
| ); | ||
| server.listen(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| server.close(); | ||
| }); | ||
|
|
||
| it('displays a 500 error if the request to the USPS API throws an error', async () => { | ||
| const { findByText, findByLabelText } = render( | ||
| <InPersonContext.Provider value={{ arcgisSearchEnabled: true }}> | ||
| <InPersonLocationPostOfficeSearchStep {...DEFAULT_PROPS} /> | ||
| </InPersonContext.Provider>, | ||
| ); | ||
|
|
||
| await userEvent.type( | ||
| await findByLabelText('in_person_proofing.body.location.po_search.address_search_label'), | ||
| '222 Merchandise Mart Plaza', | ||
| ); | ||
|
|
||
| await userEvent.click( | ||
| await findByText('in_person_proofing.body.location.po_search.search_button'), | ||
| ); | ||
|
|
||
| const error = await findByText('idv.failure.exceptions.internal_error'); | ||
| expect(error).to.exist(); | ||
| }); | ||
| }); | ||
|
|
||
| context('initial API request is successful', () => { | ||
| let server: SetupServerApi; | ||
| beforeEach(() => { | ||
| server = setupServer( | ||
| rest.post(LOCATIONS_URL, (_req, res, ctx) => res(ctx.json([{ name: 'Baltimore' }]))), | ||
| rest.post(ADDRESS_SEARCH_URL, (_req, res, ctx) => res(ctx.json(DEFAULT_RESPONSE))), | ||
| ); | ||
| server.listen(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| server.close(); | ||
| }); | ||
|
|
||
| it('allows search by address when enabled', async () => { | ||
| const { findByText, findByLabelText } = render( | ||
| <InPersonContext.Provider value={{ arcgisSearchEnabled: true }}> | ||
| <InPersonLocationPostOfficeSearchStep {...DEFAULT_PROPS} /> | ||
| </InPersonContext.Provider>, | ||
| ); | ||
|
|
||
| await userEvent.type( | ||
| await findByLabelText('in_person_proofing.body.location.po_search.address_search_label'), | ||
| '100 main', | ||
| ); | ||
| await userEvent.click( | ||
| await findByText('in_person_proofing.body.location.po_search.search_button'), | ||
| ); | ||
| await findByText('in_person_proofing.body.location.po_search.results_description'); | ||
| }); | ||
|
|
||
| it('validates input and shows inline error', async () => { | ||
| const { findByText } = render( | ||
| <InPersonContext.Provider value={{ arcgisSearchEnabled: true }}> | ||
| <InPersonLocationPostOfficeSearchStep {...DEFAULT_PROPS} /> | ||
| </InPersonContext.Provider>, | ||
| ); | ||
|
|
||
| await userEvent.click( | ||
| await findByText('in_person_proofing.body.location.po_search.search_button'), | ||
| ); | ||
|
|
||
| await findByText('in_person_proofing.body.location.inline_error'); | ||
| }); | ||
|
|
||
| it('displays no post office results if a successful search is followed by an unsuccessful search', async () => { | ||
| const { findByText, findByLabelText, queryByRole } = render( | ||
| <InPersonContext.Provider value={{ arcgisSearchEnabled: true }}> | ||
| <InPersonLocationPostOfficeSearchStep {...DEFAULT_PROPS} /> | ||
| </InPersonContext.Provider>, | ||
| ); | ||
|
|
||
| await userEvent.type( | ||
| await findByLabelText('in_person_proofing.body.location.po_search.address_search_label'), | ||
| '594 Broadway New York', | ||
| ); | ||
| await userEvent.click( | ||
| await findByText('in_person_proofing.body.location.po_search.search_button'), | ||
| ); | ||
|
|
||
| await userEvent.type( | ||
| await findByLabelText('in_person_proofing.body.location.po_search.address_search_label'), | ||
| 'asdfkf', | ||
| ); | ||
| await userEvent.click( | ||
| await findByText('in_person_proofing.body.location.po_search.search_button'), | ||
| ); | ||
|
|
||
| const results = queryByRole('status', { | ||
| name: 'in_person_proofing.body.location.po_search.results_description', | ||
| }); | ||
| expect(results).not.to.exist(); | ||
| }); | ||
|
eileen-nava marked this conversation as resolved.
|
||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,5 +41,9 @@ export async function request<Response>( | |
| } | ||
|
|
||
| const response = await window.fetch(url, { ...fetchOptions, headers, body }); | ||
| return json ? response.json() : response.text(); | ||
| if (response.ok) { | ||
| return json ? response.json() : response.text(); | ||
| } | ||
|
|
||
| throw new Error(await response.json()); | ||
|
Comment on lines
+44
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to use SWR's
Comment on lines
+44
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be good to have spec coverage for the new behaviors here:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aduth thanks! I'll open a ticket for added coverage.
What's the standard approach to this? Is it better to assume Also, re: NewRelic, do you mean... the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I guess my first question is what details do we want from what's thrown? It doesn't look like we really care what the detail is at the moment, since we're not using it. I think we could even go as far as removing the parameter altogether. But otherwise I think it could be fine to use a general text that's descriptive enough of what happened (e.g. something like
I mean if the API responds with anything other than 200 status code, but sent a JSON payload like... ...we'd risk logging that in NewRelic. I think it can also be helpful to assign a generic name for the error so that we can aggregate it more easily (i.e. otherwise how would we know how often this line of code is throwing?). |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.