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

Site services clean up #716

Merged
merged 9 commits into from
May 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import React from 'react';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { createMockHandler, createMockSite } from 'test-utils/fixtures';
import { createMockProfileResponse } from 'test-utils/fixtures/mockUser';
import { userApiMocks } from 'test-utils/mock';
import { API_BASE_URL } from 'test-utils/mock/htApiMocks';
import { mockUserEndpoints } from 'test-utils/mock';
import { API_BASE_URL } from 'test-utils/mock/mockSiteEndpoints';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';

const server = setupServer(...userApiMocks);
const server = setupServer(...mockUserEndpoints);
afterEach(() => cleanup());
beforeAll(() => server.listen());
afterAll(() => server.close()); // Disable API mocking after the tests are done.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { setupServer } from 'msw/node';
import React from 'react';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { createMockHandler } from 'test-utils/fixtures';
import { userApiMocks } from 'test-utils/mock';
import { mockUserEndpoints } from 'test-utils/mock';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';

const server = setupServer(...userApiMocks);
const server = setupServer(...mockUserEndpoints);
afterEach(() => cleanup());
beforeAll(() => server.listen());
afterAll(() => server.close()); // Disable API mocking after the tests are done.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import '@testing-library/jest-dom';
import { HaztrakProfileResponse } from 'store/userSlice/user.slice';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { createMockRcrainfoSite } from 'test-utils/fixtures';
import { userApiMocks } from 'test-utils/mock';
import { API_BASE_URL } from 'test-utils/mock/htApiMocks';
import { mockUserEndpoints } from 'test-utils/mock';
import { API_BASE_URL } from 'test-utils/mock/mockSiteEndpoints';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
import { HandlerSearchForm } from './HandlerSearchForm';

Expand Down Expand Up @@ -45,7 +45,7 @@ export const mockHandlerSearches = [
}),
];

const server = setupServer(...userApiMocks, ...mockHandlerSearches);
const server = setupServer(...mockUserEndpoints, ...mockHandlerSearches);
afterEach(() => {
cleanup();
});
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/Manifest/ManifestForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import '@testing-library/jest-dom';
import { fireEvent, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { ManifestForm } from 'components/Manifest';
import { setupServer } from 'msw/node';
import React from 'react';
import { cleanup, renderWithProviders } from 'test-utils';
import { mockUserEndpoints, mockWasteEndpoints } from 'test-utils/mock';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
import { setupServer } from 'msw/node';
import { userApiMocks, wasteApiMocks } from 'test-utils/mock';

const server = setupServer(...userApiMocks, ...wasteApiMocks);
const server = setupServer(...mockUserEndpoints, ...mockWasteEndpoints);
afterEach(() => cleanup());
beforeAll(() => server.listen());
afterAll(() => server.close());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react';
import { HaztrakProfileResponse } from 'store/userSlice/user.slice';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { createMockMTNHandler } from 'test-utils/fixtures';
import { userApiMocks } from 'test-utils/mock';
import { mockUserEndpoints } from 'test-utils/mock';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
import { undefined } from 'zod';

Expand All @@ -21,7 +21,7 @@ const mockProfile: HaztrakProfileResponse = {
},
};

const server = setupServer(...userApiMocks);
const server = setupServer(...mockUserEndpoints);
afterEach(() => cleanup());
beforeAll(() => server.listen());
afterAll(() => server.close()); // Disable API mocking after the tests are done.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { setupServer } from 'msw/node';
import React from 'react';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { createMockTransporter } from 'test-utils/fixtures';
import { userApiMocks } from 'test-utils/mock';
import { mockUserEndpoints } from 'test-utils/mock';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
import { TransporterTable } from './index';

Expand All @@ -24,7 +24,7 @@ const TRAN_ARRAY: Array<Transporter> = [
...createMockTransporter({ epaSiteId: HANDLER_ID_2, name: HANDLER_NAME_2, order: 2 }),
},
];
const server = setupServer(...userApiMocks);
const server = setupServer(...mockUserEndpoints);
afterEach(() => cleanup());
beforeAll(() => server.listen());
afterAll(() => server.close());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import { setupServer } from 'msw/node';
import React from 'react';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { mockUserEndpoints, mockWasteEndpoints } from 'test-utils/mock';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
import { WasteLineForm } from './WasteLineForm';
import { setupServer } from 'msw/node';
import { userApiMocks, wasteApiMocks } from 'test-utils/mock';

const server = setupServer(...userApiMocks, ...wasteApiMocks);
const server = setupServer(...mockUserEndpoints, ...mockWasteEndpoints);
afterEach(() => {
cleanup();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import React from 'react';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { userApiMocks } from 'test-utils/mock';
import { API_BASE_URL } from 'test-utils/mock/htApiMocks';
import { mockUserEndpoints } from 'test-utils/mock';
import { API_BASE_URL } from 'test-utils/mock/mockSiteEndpoints';
import { afterAll, afterEach, beforeAll, describe, expect, test, vi } from 'vitest';

const testTaskID = 'testTaskId';

const server = setupServer(...userApiMocks);
const server = setupServer(...mockUserEndpoints);
server.use(
http.post(`${API_BASE_URL}rcra/manifest/emanifest/sync`, () => {
// Mock Sync Site Manifests response
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/User/UserInfoForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import React from 'react';
import { HaztrakUser, ProfileSlice } from 'store';
import { renderWithProviders, screen } from 'test-utils';
import { createMockHaztrakUser } from 'test-utils/fixtures';
import { userApiMocks } from 'test-utils/mock';
import { mockUserEndpoints } from 'test-utils/mock';
import { afterAll, afterEach, beforeAll, describe, expect, test, vi } from 'vitest';

const server = setupServer(...userApiMocks);
const server = setupServer(...mockUserEndpoints);

// pre-/post-test hooks
beforeAll(() => server.listen());
Expand Down
6 changes: 3 additions & 3 deletions client/src/features/Dashboard/Dashboard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { Dashboard } from 'features/Dashboard/Dashboard';
import { setupServer } from 'msw/node';
import React, { createElement } from 'react';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { userApiMocks } from 'test-utils/mock';
import { htApiMocks } from 'test-utils/mock/htApiMocks';
import { mockUserEndpoints } from 'test-utils/mock';
import { mockSiteEndpoints } from 'test-utils/mock/mockSiteEndpoints';
import { afterAll, afterEach, beforeAll, describe, expect, test, vi } from 'vitest';

const USERNAME = 'testuser1';

const server = setupServer(...htApiMocks, ...userApiMocks);
const server = setupServer(...mockSiteEndpoints, ...mockUserEndpoints);

beforeAll(() => {
vi.mock('recharts', async (importOriginal) => {
Expand Down
6 changes: 3 additions & 3 deletions client/src/features/NewManifest/NewManifest.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import React from 'react';
import { HaztrakProfileResponse } from 'store/userSlice/user.slice';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { createMockSite } from 'test-utils/fixtures';
import { userApiMocks } from 'test-utils/mock';
import { API_BASE_URL } from 'test-utils/mock/htApiMocks';
import { mockUserEndpoints } from 'test-utils/mock';
import { API_BASE_URL } from 'test-utils/mock/mockSiteEndpoints';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';

const mySiteId = 'VATESTGEN001';
Expand All @@ -29,7 +29,7 @@ const mockProfile: HaztrakProfileResponse = {
},
};

const server = setupServer(...userApiMocks);
const server = setupServer(...mockUserEndpoints);
server.use(
http.get(`${API_BASE_URL}/api/user/profile`, () => {
return HttpResponse.json({ ...mockProfile }, { status: 200 });
Expand Down
4 changes: 2 additions & 2 deletions client/src/features/SiteList/SiteList.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setupServer } from 'msw/node';
import React from 'react';
import { renderWithProviders, screen } from 'test-utils';
import { createMockHandler, createMockSite } from 'test-utils/fixtures/mockHandler';
import { htApiMocks, userApiMocks } from 'test-utils/mock';
import { mockSiteEndpoints, mockUserEndpoints } from 'test-utils/mock';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
import { SiteList } from './SiteList';

Expand All @@ -13,7 +13,7 @@ const mockSites = [
createMockSite({ handler: mockHandler1 }),
createMockSite({ handler: mockHandler2 }),
];
const server = setupServer(...userApiMocks, ...htApiMocks);
const server = setupServer(...mockUserEndpoints, ...mockSiteEndpoints);

// pre-/post-test hooks
beforeAll(() => server.listen());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import '@testing-library/jest-dom';
import { cleanup, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Manifest } from 'components/Manifest';
import { setupServer } from 'msw/node';
import React from 'react';
import { renderWithProviders, screen } from 'test-utils';
import { createMockManifest } from 'test-utils/fixtures';
import { mockManifestEndpoints } from 'test-utils/mock';
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';
import { useSaveManifest } from './useSaveManifest';
import { Manifest } from 'components/Manifest';
import userEvent from '@testing-library/user-event';
import { createMockManifest } from 'test-utils/fixtures';
import { setupServer } from 'msw/node';
import { manifestMocks } from 'test-utils/mock';

const TestComponent = ({ manifest }: { manifest?: Manifest }) => {
const { data, isLoading, error, taskId, saveManifest } = useSaveManifest();
Expand All @@ -24,7 +24,7 @@ const TestComponent = ({ manifest }: { manifest?: Manifest }) => {
);
};

const server = setupServer(...manifestMocks);
const server = setupServer(...mockManifestEndpoints);
beforeAll(() => server.listen());
afterAll(() => server.close());
afterEach(() => cleanup());
Expand Down
6 changes: 3 additions & 3 deletions client/src/hooks/useUserSiteIds/useUserSiteIds.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import React from 'react';
import { renderWithProviders, screen } from 'test-utils';
import { createMockHandler, createMockSite } from 'test-utils/fixtures';
import { createMockProfileResponse } from 'test-utils/fixtures/mockUser';
import { userApiMocks, wasteApiMocks } from 'test-utils/mock';
import { API_BASE_URL } from 'test-utils/mock/htApiMocks';
import { mockUserEndpoints, mockWasteEndpoints } from 'test-utils/mock';
import { API_BASE_URL } from 'test-utils/mock/mockSiteEndpoints';
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';

function TestComponent() {
Expand All @@ -23,7 +23,7 @@ function TestComponent() {
);
}

const server = setupServer(...userApiMocks, ...wasteApiMocks);
const server = setupServer(...mockUserEndpoints, ...mockWasteEndpoints);
beforeAll(() => server.listen());
afterAll(() => server.close());
afterEach(() => cleanup());
Expand Down
5 changes: 4 additions & 1 deletion client/src/store/htApi.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ export const haztrakApi = createApi({
providesTags: ['site'],
}),
getMTN: build.query<Array<MtnDetails>, string | undefined>({
query: (siteId) => ({ url: siteId ? `rcra/mtn/${siteId}` : 'rcra/mtn', method: 'get' }),
query: (siteId) => ({
url: siteId ? `rcra/manifest/mtn/${siteId}` : 'rcra/manifest/mtn',
method: 'get',
}),
providesTags: ['manifest'],
}),
getManifest: build.query<Manifest, string>({
Expand Down
4 changes: 2 additions & 2 deletions client/src/store/userSlice/user.slice.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { setupServer } from 'msw/node';
import { useEffect, useState } from 'react';
import { useGetUserQuery, useUpdateUserMutation } from 'store';
import { cleanup, renderWithProviders, screen } from 'test-utils';
import { userApiMocks } from 'test-utils/mock';
import { mockUserEndpoints } from 'test-utils/mock';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';

const server = setupServer(...userApiMocks);
const server = setupServer(...mockUserEndpoints);
afterEach(() => {
cleanup();
});
Expand Down
26 changes: 0 additions & 26 deletions client/src/test-utils/mock/htApiMocks.ts

This file was deleted.

8 changes: 4 additions & 4 deletions client/src/test-utils/mock/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { userApiMocks } from './userApiMocks';
export { htApiMocks } from './htApiMocks';
export { wasteApiMocks } from './wasteApiMocks';
export { manifestMocks } from './manifestMocks';
export { mockUserEndpoints } from 'test-utils/mock/mockUserEndpoints';
export { mockSiteEndpoints } from 'test-utils/mock/mockSiteEndpoints';
export { mockWasteEndpoints } from 'test-utils/mock/mockWasteEndpoints';
export { mockManifestEndpoints } from 'test-utils/mock/mockManifestEndpoints';
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Manifest } from 'components/Manifest';
import { http, HttpResponse } from 'msw';
import { createMockManifest } from '../fixtures';
import { Manifest } from 'components/Manifest';

export const API_BASE_URL = import.meta.env.VITE_HT_API_URL;
const mockMTN = createMockManifest().manifestTrackingNumber;

export const manifestMocks = [
const generateRandomMTN = (): string => {
return Math.floor(100000000 + Math.random() * 900000000).toString();
};

export const mockManifestEndpoints = [
/** mock GET Manifest*/
http.get(`${API_BASE_URL}/api/rcra/manifest/${mockMTN}`, (info) => {
return HttpResponse.json(createMockManifest(), { status: 200 });
Expand All @@ -14,10 +18,7 @@ export const manifestMocks = [
http.post(`${API_BASE_URL}/api/rcra/manifest`, async (info) => {
let bodyManifest = (await info.request.json()) as Manifest;
if (!bodyManifest.manifestTrackingNumber)
bodyManifest.manifestTrackingNumber = `${Math.floor(Math.random() * 1000000000)}DFT`.padEnd(
9,
'0'
);
bodyManifest.manifestTrackingNumber = `${generateRandomMTN()}DFT`.padEnd(9, '0');
return HttpResponse.json(bodyManifest, { status: 200 });
}),
/** Mock update local Manifests*/
Expand Down
17 changes: 17 additions & 0 deletions client/src/test-utils/mock/mockSiteEndpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { http, HttpResponse } from 'msw';
import { createMockHandler, createMockSite } from '../fixtures';

export const API_BASE_URL = import.meta.env.VITE_HT_API_URL;
const mockEpaId = createMockHandler().epaSiteId;
const mockSites = [createMockSite(), createMockSite()];

export const mockSiteEndpoints = [
/** List user sites*/
http.get(`${API_BASE_URL}/api/site`, (info) => {
return HttpResponse.json(mockSites, { status: 200 });
}),
/** Site Details*/
http.get(`${API_BASE_URL}/api/site/${mockEpaId}`, (info) => {
return HttpResponse.json(mockSites[0], { status: 200 });
}),
];
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

/** mock Rest API*/
const API_BASE_URL = import.meta.env.VITE_HT_API_URL;
export const userApiMocks = [
export const mockUserEndpoints = [
/** GET User */
http.get(`${API_BASE_URL}/api/user`, () => {
return HttpResponse.json({ ...createMockHaztrakUser() }, { status: 200 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mockDotIdNumbers, mockFederalWasteCodes } from 'test-utils/fixtures/moc

/** mock Rest API*/
const API_BASE_URL = import.meta.env.VITE_HT_API_URL;
export const wasteApiMocks = [
export const mockWasteEndpoints = [
/** GET User */
http.get(`${API_BASE_URL}/api/rcra/waste/code/federal`, (info) => {
return HttpResponse.json(mockFederalWasteCodes, { status: 200 });
Expand Down
Loading
Loading