Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from '@testing-library/react';
import { useSandbox } from '@18f/identity-test-helpers';
import userEvent from '@testing-library/user-event';
import { setupServer } from 'msw/node';
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import type { SetupServer } from 'msw/node';
import { SWRConfig } from 'swr';
import AddressInput from './address-input';
Expand Down Expand Up @@ -30,8 +30,8 @@ describe('AddressInput', () => {
let server: SetupServer;
before(() => {
server = setupServer(
rest.post(LOCATIONS_URL, (_req, res, ctx) => res(ctx.json([{ name: 'Baltimore' }]))),
rest.post(ADDRESSES_URL, (_req, res, ctx) => res(ctx.json(DEFAULT_RESPONSE))),
http.post(LOCATIONS_URL, () => HttpResponse.json([{ name: 'Baltimore' }])),
http.post(ADDRESSES_URL, () => HttpResponse.json(DEFAULT_RESPONSE)),
);
server.listen();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import sinon from 'sinon';
import { useSandbox } from '@18f/identity-test-helpers';
import userEvent from '@testing-library/user-event';
import { setupServer } from 'msw/node';
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import type { SetupServer } from 'msw/node';
import { SWRConfig } from 'swr';
import FullAddressSearch from './full-address-search';
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('FullAddressSearch', () => {
let server: SetupServer;
before(() => {
server = setupServer(
rest.post(locationsURL, (_req, res, ctx) => res(ctx.json([{ name: 'Baltimore' }]))),
http.post(locationsURL, () => HttpResponse.json([{ name: 'Baltimore' }])),
);
server.listen();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks';
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import type { SetupServer } from 'msw/node';
import useValidatedUspsLocations from './use-validated-usps-locations';
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('useValidatedUspsLocations', () => {

beforeEach(() => {
server.resetHandlers();
server.use(rest.post(locationsURL, (_req, res, ctx) => res(ctx.json(USPS_RESPONSE))));
server.use(http.post(locationsURL, () => HttpResponse.json(USPS_RESPONSE)));
});

it('returns location results', async () => {
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/packages/build-sass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@aduth/is-dependency": "^1.0.0",
"browserslist": "^4.22.3",
"chokidar": "^3.5.3",
"chokidar": "^3.6.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not strictly relevant, but there was some conflicts with TypeScript types in the earlier build which are resolved in the newer version (see changelog).

"lightningcss": "^1.23.0",
"sass-embedded": "^1.70.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
import { i18n } from '@18f/identity-i18n';
import { setupServer } from 'msw/node';
import type { SetupServer } from 'msw/node';
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import { SWRConfig } from 'swr';
import { usePropertyValue } from '@18f/identity-test-helpers';
import { ComponentType } from 'react';
Expand Down Expand Up @@ -78,8 +78,8 @@ describe('InPersonLocationFullAddressEntryPostOfficeSearchStep', () => {
server.resetHandlers();
// todo: should we return USPS_RESPONSE here?
server.use(
rest.post(locationsURL, (_req, res, ctx) => res(ctx.json([{ name: 'Baltimore' }]))),
rest.put(locationsURL, (_req, res, ctx) => res(ctx.json({ success: true }))),
http.post(locationsURL, () => HttpResponse.json([{ name: 'Baltimore' }])),
http.put(locationsURL, () => HttpResponse.json({ success: true })),
);
});

Expand All @@ -94,7 +94,7 @@ describe('InPersonLocationFullAddressEntryPostOfficeSearchStep', () => {

context('USPS request returns an error', () => {
beforeEach(() => {
server.use(rest.post(locationsURL, (_req, res, ctx) => res(ctx.status(500))));
server.use(http.post(locationsURL, () => new HttpResponse(null, { status: 500 })));
});

it('displays a try again error message', async () => {
Expand Down Expand Up @@ -259,7 +259,7 @@ describe('InPersonLocationFullAddressEntryPostOfficeSearchStep', () => {

it('displays correct pluralization for multiple location results', async () => {
server.resetHandlers();
server.use(rest.post(locationsURL, (_req, res, ctx) => res(ctx.json(USPS_RESPONSE))));
server.use(http.post(locationsURL, () => HttpResponse.json(USPS_RESPONSE)));
const { findByLabelText, findByText } = render(
<InPersonLocationFullAddressEntryPostOfficeSearchStep {...DEFAULT_PROPS} />,
{ wrapper },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
import { i18n } from '@18f/identity-i18n';
import { usePropertyValue } from '@18f/identity-test-helpers';
import { setupServer } from 'msw/node';
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import type { SetupServer } from 'msw/node';
import { SWRConfig } from 'swr';
import { ComponentType } from 'react';
Expand Down Expand Up @@ -96,9 +96,7 @@ describe('InPersonLocationPostOfficeSearchStep', () => {

context('initial ArcGIS API request throws an error', () => {
beforeEach(() => {
server.use(
rest.post(addressSearchURL, (_req, res, ctx) => res(ctx.json([]), ctx.status(422))),
);
server.use(http.post(addressSearchURL, () => HttpResponse.json([], { status: 422 })));
});

it('displays a try again error message', async () => {
Expand All @@ -124,10 +122,8 @@ describe('InPersonLocationPostOfficeSearchStep', () => {
context('initial USPS API request throws an error', () => {
beforeEach(() => {
server.use(
rest.post(addressSearchURL, (_req, res, ctx) =>
res(ctx.json(DEFAULT_RESPONSE), ctx.status(200)),
),
rest.post(locationsURL, (_req, res, ctx) => res(ctx.status(500))),
http.post(addressSearchURL, () => HttpResponse.json(DEFAULT_RESPONSE)),
http.post(locationsURL, () => new HttpResponse(null, { status: 500 })),
);
});

Expand All @@ -154,10 +150,8 @@ describe('InPersonLocationPostOfficeSearchStep', () => {
context('initial API request is successful', () => {
beforeEach(() => {
server.use(
rest.post(addressSearchURL, (_req, res, ctx) =>
res(ctx.json(DEFAULT_RESPONSE), ctx.status(200)),
),
rest.post(locationsURL, (_req, res, ctx) => res(ctx.json([{ name: 'Baltimore' }]))),
http.post(addressSearchURL, () => HttpResponse.json(DEFAULT_RESPONSE)),
http.post(locationsURL, () => HttpResponse.json([{ name: 'Baltimore' }])),
);
});

Expand Down Expand Up @@ -273,10 +267,8 @@ describe('InPersonLocationPostOfficeSearchStep', () => {
it('displays correct pluralization for multiple location results', async () => {
server.resetHandlers();
server.use(
rest.post(addressSearchURL, (_req, res, ctx) =>
res(ctx.json(DEFAULT_RESPONSE), ctx.status(200)),
),
rest.post(locationsURL, (_req, res, ctx) => res(ctx.json(MULTI_LOCATION_RESPONSE))),
http.post(addressSearchURL, () => HttpResponse.json(DEFAULT_RESPONSE)),
http.post(locationsURL, () => HttpResponse.json(MULTI_LOCATION_RESPONSE)),
);
const { findByLabelText, findByText } = render(
<InPersonLocationPostOfficeSearchStep {...DEFAULT_PROPS} />,
Expand All @@ -303,10 +295,8 @@ describe('InPersonLocationPostOfficeSearchStep', () => {
context('subsequent network failures clear results', () => {
beforeEach(() => {
server.use(
rest.post(addressSearchURL, (_req, res, ctx) =>
res(ctx.json(DEFAULT_RESPONSE), ctx.status(200)),
),
rest.post(locationsURL, (_req, res, ctx) => res(ctx.json([{ name: 'Baltimore' }]))),
http.post(addressSearchURL, () => HttpResponse.json(DEFAULT_RESPONSE)),
http.post(locationsURL, () => HttpResponse.json([{ name: 'Baltimore' }])),
);
});

Expand All @@ -328,25 +318,22 @@ describe('InPersonLocationPostOfficeSearchStep', () => {
expect(result).to.exist();

server.use(
rest.post(addressSearchURL, (_req, res, ctx) =>
res(
ctx.json([
{
address: '500 Main St E, Bronwood, Georgia, 39826',
location: {
latitude: 31.831686000000005,
longitude: -84.363768,
},
street_address: '500 Main St E',
city: 'Bronwood',
state: 'GA',
zip_code: '39826',
http.post(addressSearchURL, () =>
HttpResponse.json([
{
address: '500 Main St E, Bronwood, Georgia, 39826',
location: {
latitude: 31.831686000000005,
longitude: -84.363768,
},
]),
ctx.status(200),
),
street_address: '500 Main St E',
city: 'Bronwood',
state: 'GA',
zip_code: '39826',
},
]),
),
rest.post(locationsURL, (_req, res, ctx) => res(ctx.status(500))),
http.post(locationsURL, () => new HttpResponse(null, { status: 500 })),
);

await userEvent.type(
Expand All @@ -365,11 +352,9 @@ describe('InPersonLocationPostOfficeSearchStep', () => {
context('user deletes text from searchbox after location results load', () => {
beforeEach(() => {
server.use(
rest.post(addressSearchURL, (_req, res, ctx) =>
res(ctx.json(DEFAULT_RESPONSE), ctx.status(200)),
),
rest.post(locationsURL, (_req, res, ctx) => res(ctx.json([{ name: 'Baltimore' }]))),
rest.put(locationsURL, (_req, res, ctx) => res(ctx.json({ success: true }))),
http.post(addressSearchURL, () => HttpResponse.json(DEFAULT_RESPONSE)),
http.post(locationsURL, () => HttpResponse.json([{ name: 'Baltimore' }])),
http.put(locationsURL, () => HttpResponse.json({ success: true })),
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import quibble from 'quibble';
import { screen, waitFor } from '@testing-library/dom';
import baseUserEvent from '@testing-library/user-event';
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import type { SetupServer } from 'msw/node';
import type { SinonStub } from 'sinon';
Expand Down Expand Up @@ -226,11 +226,7 @@ describe('ManageableAuthenticatorElement', () => {

context('successful response from server when submitting rename', () => {
beforeEach(() => {
server.use(
rest.put('/api/manage', (_req, res, ctx) =>
res(ctx.json({ success: true }), ctx.status(200)),
),
);
server.use(http.put('/api/manage', () => HttpResponse.json({ success: true })));
});

it('returns the user to summary details with new name for successful save', async () => {
Expand Down Expand Up @@ -278,9 +274,7 @@ describe('ManageableAuthenticatorElement', () => {
context('failed response from server when submitting rename', () => {
beforeEach(() => {
server.use(
rest.put('/api/manage', (_req, res, ctx) =>
res(ctx.json({ error: 'Uh oh!' }), ctx.status(400)),
),
http.put('/api/manage', () => HttpResponse.json({ error: 'Uh oh!' }, { status: 400 })),
);
});

Expand Down Expand Up @@ -360,11 +354,7 @@ describe('ManageableAuthenticatorElement', () => {

context('successful response from server when deleting', () => {
beforeEach(() => {
server.use(
rest.delete('/api/manage', (_req, res, ctx) =>
res(ctx.json({ success: true }), ctx.status(200)),
),
);
server.use(http.delete('/api/manage', () => HttpResponse.json({ success: true })));
});

it('deletes the authenticator and displays a confirmation message', async () => {
Expand Down Expand Up @@ -395,9 +385,7 @@ describe('ManageableAuthenticatorElement', () => {
context('failed response from server when deleting', () => {
beforeEach(() => {
server.use(
rest.delete('/api/manage', (_req, res, ctx) =>
res(ctx.json({ error: 'Uh oh!' }), ctx.status(400)),
),
http.delete('/api/manage', () => HttpResponse.json({ error: 'Uh oh!' }, { status: 400 })),
);
});

Expand Down
22 changes: 11 additions & 11 deletions app/javascript/packages/session/requests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import type { SetupServer } from 'msw/node';
import { SESSIONS_URL, requestSessionStatus, extendSession } from './requests';
Expand All @@ -10,8 +10,8 @@ describe('requestSessionStatus', () => {
context('session inactive', () => {
before(() => {
server = setupServer(
rest.get<{}, {}, SessionTimedOutStatusResponse>(SESSIONS_URL, (_req, res, ctx) =>
res(ctx.json({ live: false, timeout: null })),
http.get<{}, {}, SessionTimedOutStatusResponse>(SESSIONS_URL, () =>
HttpResponse.json({ live: false, timeout: null }),
),
);
server.listen();
Expand All @@ -34,8 +34,8 @@ describe('requestSessionStatus', () => {
before(() => {
timeout = new Date(Date.now() + 1000).toISOString();
server = setupServer(
rest.get<{}, {}, SessionLiveStatusResponse>(SESSIONS_URL, (_req, res, ctx) =>
res(ctx.json({ live: true, timeout })),
http.get<{}, {}, SessionLiveStatusResponse>(SESSIONS_URL, () =>
HttpResponse.json({ live: true, timeout }),
),
);
server.listen();
Expand All @@ -55,7 +55,7 @@ describe('requestSessionStatus', () => {
context('server responds with 401', () => {
before(() => {
server = setupServer(
rest.get<{}, {}>(SESSIONS_URL, (_req, res, ctx) => res(ctx.status(401))),
http.get<{}, {}>(SESSIONS_URL, () => new HttpResponse(null, { status: 401 })),
);
server.listen();
});
Expand All @@ -74,7 +74,7 @@ describe('requestSessionStatus', () => {
context('server responds with 500', () => {
before(() => {
server = setupServer(
rest.get<{}, {}>(SESSIONS_URL, (_req, res, ctx) => res(ctx.status(500))),
http.get<{}, {}>(SESSIONS_URL, () => new HttpResponse(null, { status: 500 })),
);
server.listen();
});
Expand All @@ -97,8 +97,8 @@ describe('extendSession', () => {

before(() => {
server = setupServer(
rest.put<{}, {}, SessionLiveStatusResponse>(SESSIONS_URL, (_req, res, ctx) =>
res(ctx.json({ live: true, timeout })),
http.put<{}, {}, SessionLiveStatusResponse>(SESSIONS_URL, () =>
HttpResponse.json({ live: true, timeout }),
),
);
server.listen();
Expand All @@ -118,7 +118,7 @@ describe('extendSession', () => {
context('server responds with 401', () => {
before(() => {
server = setupServer(
rest.put<{}, {}>(SESSIONS_URL, (_req, res, ctx) => res(ctx.status(401))),
http.put<{}, {}>(SESSIONS_URL, () => new HttpResponse(null, { status: 401 })),
);
server.listen();
});
Expand All @@ -137,7 +137,7 @@ describe('extendSession', () => {
context('server responds with 500', () => {
before(() => {
server = setupServer(
rest.put<{}, {}>(SESSIONS_URL, (_req, res, ctx) => res(ctx.status(500))),
http.put<{}, {}>(SESSIONS_URL, () => new HttpResponse(null, { status: 500 })),
);
server.listen();
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"jsdom": "^22.1.0",
"mocha": "^10.0.0",
"mq-polyfill": "^1.1.8",
"msw": "^1.3.2",
"msw": "^2.2.1",
"prettier": "^3.1.0",
"quibble": "^0.9.1",
"react-test-renderer": "^17.0.2",
Expand Down
Loading