diff --git a/lib/lambda/getAllForms.test.ts b/lib/lambda/getAllForms.test.ts index 3830eb071..5319fc0bd 100644 --- a/lib/lambda/getAllForms.test.ts +++ b/lib/lambda/getAllForms.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from "vitest"; -import { getAllForms, mapWebformsKeys } from "./getAllForms"; +import { getAllForms } from "./getAllForms"; import * as wfv from "libs/webforms"; vi.mock("../libs/webforms", () => ({ diff --git a/lib/lambda/getCpocs.test.ts b/lib/lambda/getCpocs.test.ts index c50f172e0..ee4acdd94 100644 --- a/lib/lambda/getCpocs.test.ts +++ b/lib/lambda/getCpocs.test.ts @@ -2,7 +2,7 @@ import { describe, it, expect } from "vitest"; import { APIGatewayEvent } from "aws-lambda"; import { handler } from "./getCpocs"; import { mockedServiceServer } from "mocks/server"; -import { emptyCpocSearchHandler, errorCpocSearchHandler } from "mocks"; +import { emptyOSCpocSearchHandler, errorOSCpocSearchHandler } from "mocks"; import { cpocsList } from "mocks/data/cpocs"; describe("getCpocs Handler", () => { @@ -18,7 +18,7 @@ describe("getCpocs Handler", () => { // TODO - should this be removed? when will the result be empty and not // just a result with an empty hit array it("should return 400 if no Cpocs are found", async () => { - mockedServiceServer.use(emptyCpocSearchHandler); + mockedServiceServer.use(emptyOSCpocSearchHandler); const event = { body: JSON.stringify({}) } as APIGatewayEvent; @@ -39,7 +39,7 @@ describe("getCpocs Handler", () => { }); it("should return 500 if an error occurs during processing", async () => { - mockedServiceServer.use(errorCpocSearchHandler); + mockedServiceServer.use(errorOSCpocSearchHandler); const event = { body: JSON.stringify({}) } as APIGatewayEvent; diff --git a/lib/lambda/getSubTypes.test.ts b/lib/lambda/getSubTypes.test.ts index abb94ef66..0662063b1 100644 --- a/lib/lambda/getSubTypes.test.ts +++ b/lib/lambda/getSubTypes.test.ts @@ -12,7 +12,7 @@ import { medicaidSubtypes, chipSubtypes, } from "mocks/data/types"; -import { TestSubtypeItemResult, errorSubtypeSearchHandler } from "mocks"; +import { TestSubtypeItemResult, errorOSSubtypeSearchHandler } from "mocks"; import { mockedServiceServer as mockedServer } from "mocks/server"; describe("getSubTypes Handler", () => { @@ -40,7 +40,7 @@ describe("getSubTypes Handler", () => { }); it("should return 500 if there is a server error", async () => { - mockedServer.use(errorSubtypeSearchHandler); + mockedServer.use(errorOSSubtypeSearchHandler); const event = { body: JSON.stringify({ diff --git a/lib/lambda/getTypes.test.ts b/lib/lambda/getTypes.test.ts index 370a417b8..3ff0e65ff 100644 --- a/lib/lambda/getTypes.test.ts +++ b/lib/lambda/getTypes.test.ts @@ -8,7 +8,7 @@ import { medicaidTypes, chipTypes, } from "mocks/data/types"; -import { TestTypeItemResult, errorTypeSearchHandler } from "mocks"; +import { TestTypeItemResult, errorOSTypeSearchHandler } from "mocks"; import { mockedServiceServer as mockedServer } from "mocks/server"; describe("getTypes Handler", () => { @@ -33,7 +33,7 @@ describe("getTypes Handler", () => { }); it("should return 500 if there is a server error", async () => { - mockedServer.use(errorTypeSearchHandler); + mockedServer.use(errorOSTypeSearchHandler); const event = { body: JSON.stringify({ authorityId: MEDICAID_SPA_AUTHORITY_ID }), diff --git a/lib/lambda/sinkMainProcessors.test.ts b/lib/lambda/sinkMainProcessors.test.ts index 4b219a3ef..89f011bfc 100644 --- a/lib/lambda/sinkMainProcessors.test.ts +++ b/lib/lambda/sinkMainProcessors.test.ts @@ -17,7 +17,7 @@ import { NOT_FOUND_ITEM_ID, convertObjToBase64, createKafkaRecord, - errorMainMultiDocumentHandler, + errorOSMainMultiDocumentHandler, } from "mocks"; import { mockedServiceServer as mockedServer } from "mocks/server"; import { @@ -845,7 +845,7 @@ describe("insertNewSeatoolRecordsFromKafkaIntoMako", () => { }); it("handles errors in getting mako timestamps", async () => { - mockedServer.use(errorMainMultiDocumentHandler); + mockedServer.use(errorOSMainMultiDocumentHandler); await insertNewSeatoolRecordsFromKafkaIntoMako( [ diff --git a/lib/vitest.setup.ts b/lib/vitest.setup.ts index 61012f372..494cde920 100644 --- a/lib/vitest.setup.ts +++ b/lib/vitest.setup.ts @@ -1,8 +1,6 @@ import { afterAll, afterEach, beforeAll, beforeEach, vi } from "vitest"; import { - API_CONFIG, API_ENDPOINT, - AUTH_CONFIG, IDENTITY_POOL_ID, OPENSEARCH_DOMAIN, OPENSEARCH_INDEX_NAMESPACE, @@ -22,12 +20,7 @@ import { } from "mocks"; import { ConfigResourceTypes } from "kafkajs"; import { mockedServiceServer as mockedServer } from "mocks/server"; -import { Amplify } from "aws-amplify"; type CreateType = T & { default: T }; -Amplify.configure({ - API: API_CONFIG, - Auth: AUTH_CONFIG, -}); vi.mock("kafkajs", async (importOriginal) => ({ ...(await importOriginal()), diff --git a/mocks/consts.ts b/mocks/consts.ts index 6228e82b2..1032a7a4b 100644 --- a/mocks/consts.ts +++ b/mocks/consts.ts @@ -37,8 +37,8 @@ export const AUTH_CONFIG = { userPoolWebClientId: USER_POOL_CLIENT_ID, oauth: { domain: USER_POOL_CLIENT_DOMAIN, - redirectSignIn: "http://localhost", - redirectSignOut: "http://localhost", + redirectSignIn: "http://localhost:5000/", + redirectSignOut: "http://localhost:5000/", scope: ["email", "openid"], responseType: "code", }, diff --git a/mocks/data/users/index.ts b/mocks/data/users/index.ts index 005d82e65..b51a1f2bd 100644 --- a/mocks/data/users/index.ts +++ b/mocks/data/users/index.ts @@ -3,7 +3,7 @@ import { reviewers, makoReviewer, superReviewer } from "./cmsReviewer"; import { helpDeskUsers, helpDeskUser } from "./helpDeskUsers"; import { readOnlyUsers, readOnlyUser } from "./readOnlyCMSUsers"; import { stateSubmitters, makoStateSubmitter, coStateSubmitter } from "./stateSubmitters"; -import { convertUserAttributes } from "mocks/handlers/authUtils"; +import { convertUserAttributes } from "mocks/handlers/auth.utils"; export const noRoleUser: TestUserData = { UserAttributes: [ diff --git a/mocks/handlers/api/cpocs.ts b/mocks/handlers/api/cpocs.ts index 2d8dd70fd..80901c2a7 100644 --- a/mocks/handlers/api/cpocs.ts +++ b/mocks/handlers/api/cpocs.ts @@ -1,30 +1,32 @@ import { http, HttpResponse } from "msw"; import { cpocsList } from "../../data/cpocs"; -const defaultCpocHandler = http.post(/\/getCpocs$/, async () => - HttpResponse.json({ - took: 3, - timed_out: false, - _shards: { - total: 5, - successful: 5, - skipped: 0, - failed: 0, - }, - hits: { - total: { - value: 654, - relation: "eq", +const defaultApiCpocHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/getCpocs", + async () => + HttpResponse.json({ + took: 3, + timed_out: false, + _shards: { + total: 5, + successful: 5, + skipped: 0, + failed: 0, }, - max_score: 1, - hits: cpocsList, - }, - }), + hits: { + total: { + value: 654, + relation: "eq", + }, + max_score: 1, + hits: cpocsList, + }, + }), ); -export const errorCpocHandler = http.post( - /\/getCpocs/, +export const errorApiCpocHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/getCpocs", () => new HttpResponse(null, { status: 500 }), ); -export const cpocHandlers = [defaultCpocHandler]; +export const cpocHandlers = [defaultApiCpocHandler]; diff --git a/mocks/handlers/api/index.ts b/mocks/handlers/api/index.ts index 61f072f71..95756a555 100644 --- a/mocks/handlers/api/index.ts +++ b/mocks/handlers/api/index.ts @@ -1,6 +1,7 @@ import { cpocHandlers } from "./cpocs"; import { itemHandlers } from "./items"; import { packageActionHandlers } from "./packageActions"; +import { searchHandlers } from "./search"; import { submissionHandlers } from "./submissions"; import { typeHandlers } from "./types"; @@ -8,13 +9,15 @@ export const apiHandlers = [ ...cpocHandlers, ...itemHandlers, ...packageActionHandlers, + ...searchHandlers, ...submissionHandlers, ...typeHandlers, ]; -export { errorCpocHandler } from "./cpocs"; -export { errorItemHandler, errorItemExistsHandler } from "./items"; -export { errorPackageActionsHandler } from "./packageActions"; -export { errorAttachmentUrlHandler } from "./submissions"; -export { errorSubTypesHandler, errorTypeHandler } from "./types"; +export { errorApiCpocHandler } from "./cpocs"; +export { errorApiItemHandler, errorApiItemExistsHandler } from "./items"; +export { errorApiPackageActionsHandler } from "./packageActions"; +export { errorApiSearchHandler } from "./search"; +export { errorApiAttachmentUrlHandler } from "./submissions"; +export { errorApiSubTypesHandler, errorApiTypeHandler } from "./types"; export { mockCurrentAuthenticatedUser, mockUseGetUser, mockUserAttributes } from "./user"; diff --git a/mocks/handlers/api/items.ts b/mocks/handlers/api/items.ts index e5fa57e55..60eb6d236 100644 --- a/mocks/handlers/api/items.ts +++ b/mocks/handlers/api/items.ts @@ -2,22 +2,28 @@ import { http, HttpResponse } from "msw"; import items, { GET_ERROR_ITEM_ID } from "../../data/items"; import type { GetItemBody } from "../../index.d"; -const defaultItemHandler = http.post(/\/item$/, async ({ request }) => { - const { id } = await request.json(); +const defaultApiItemHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/item", + async ({ request }) => { + const { id } = await request.json(); - if (id == GET_ERROR_ITEM_ID) { - return new HttpResponse("Internal server error", { status: 500 }); - } + if (id == GET_ERROR_ITEM_ID) { + return new HttpResponse("Internal server error", { status: 500 }); + } - const item = items[id] || null; + const item = items[id] || null; - return item ? HttpResponse.json(item) : new HttpResponse(null, { status: 404 }); -}); + return item ? HttpResponse.json(item) : new HttpResponse(null, { status: 404 }); + }, +); -export const errorItemHandler = http.post(/\/item$/, () => new HttpResponse(null, { status: 500 })); +export const errorApiItemHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/item", + () => new HttpResponse(null, { status: 500 }), +); -const defaultItemExistsHandler = http.post( - /\/itemExists$/, +const defaultApiItemExistsHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/itemExists", async ({ request }) => { const { id } = await request.json(); if (id == GET_ERROR_ITEM_ID) { @@ -27,9 +33,9 @@ const defaultItemExistsHandler = http.post( }, ); -export const errorItemExistsHandler = http.post( - /\/itemExists$/, +export const errorApiItemExistsHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/itemExists", () => new HttpResponse(null, { status: 500 }), ); -export const itemHandlers = [defaultItemHandler, defaultItemExistsHandler]; +export const itemHandlers = [defaultApiItemHandler, defaultApiItemExistsHandler]; diff --git a/mocks/handlers/api/packageActions.ts b/mocks/handlers/api/packageActions.ts index 2cae91846..471e17081 100644 --- a/mocks/handlers/api/packageActions.ts +++ b/mocks/handlers/api/packageActions.ts @@ -4,8 +4,9 @@ import items from "mocks/data/items"; import { opensearch, UserRoles } from "shared-types"; import { getAvailableActions } from "shared-utils"; -const defaultPackageActionsHandler = http.post( - /\/getPackageActions$/, +const defaultApiPackageActionsHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/getPackageActions", + async ({ request }) => { const { id } = await request.json(); @@ -38,9 +39,9 @@ const defaultPackageActionsHandler = http.post( - /\/getPackageActions$/, +export const errorApiPackageActionsHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/getPackageActions", () => new HttpResponse(null, { status: 500 }), ); -export const packageActionHandlers = [defaultPackageActionsHandler]; +export const packageActionHandlers = [defaultApiPackageActionsHandler]; diff --git a/mocks/handlers/api/search.ts b/mocks/handlers/api/search.ts new file mode 100644 index 000000000..d1a51c076 --- /dev/null +++ b/mocks/handlers/api/search.ts @@ -0,0 +1,39 @@ +import { http, HttpResponse } from "msw"; +import { cpocsList } from "../../data/cpocs"; + +const defaultApiSearchHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/search/:index", + ({ params }) => { + const { index } = params; + + if (index === "cpocs") { + return HttpResponse.json({ + took: 3, + timed_out: false, + _shards: { + total: 5, + successful: 5, + skipped: 0, + failed: 0, + }, + hits: { + total: { + value: 654, + relation: "eq", + }, + max_score: 1, + hits: cpocsList, + }, + }); + } + + return new HttpResponse(null, { status: 200 }); + }, +); + +export const errorApiSearchHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/search/:index", + () => new HttpResponse("Internal server error", { status: 500 }), +); + +export const searchHandlers = [defaultApiSearchHandler]; diff --git a/mocks/handlers/api/submissions.ts b/mocks/handlers/api/submissions.ts index aa64f5989..446000141 100644 --- a/mocks/handlers/api/submissions.ts +++ b/mocks/handlers/api/submissions.ts @@ -3,24 +3,26 @@ import { SUBMISSION_ERROR_ITEM_ID } from "../../data/items"; import { SubmitRequestBody, AttachmentUrlRequestBody } from "../../index.d"; import { REGION } from "../../consts"; -const defaultUploadHandler = http.put( - /\/upload/, +const defaultApiUploadHandler = http.put( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/upload", async () => new HttpResponse(null, { status: 200 }), ); -const defaultUploadUrlHandler = http.post(/\/getUploadUrl/, () => - HttpResponse.json( - { - url: "/upload", - key: "test-key", - bucket: "test-bucket", - }, - { status: 200 }, - ), +const defaultApiUploadUrlHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/getUploadUrl", + () => + HttpResponse.json( + { + url: "/upload", + key: "test-key", + bucket: "test-bucket", + }, + { status: 200 }, + ), ); -const defaultAttachmentUrlHandler = http.post( - /\/getAttachmentUrl$/, +const defaultApiAttachmentUrlHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/getAttachmentUrl", async ({ request }) => { const { id, bucket, key, filename } = await request.json(); return HttpResponse.json({ @@ -29,13 +31,13 @@ const defaultAttachmentUrlHandler = http.post( - /\/getAttachmentUrl$/, +export const errorApiAttachmentUrlHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/getAttachmentUrl", async () => new HttpResponse(null, { status: 500 }), ); -const defaultSubmitHandler = http.post( - /\/submit$/, +const defaultApiSubmitHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/submit", async ({ request }) => { const { id } = await request.json(); @@ -48,8 +50,8 @@ const defaultSubmitHandler = http.post( ); export const submissionHandlers = [ - defaultUploadHandler, - defaultUploadUrlHandler, - defaultAttachmentUrlHandler, - defaultSubmitHandler, + defaultApiUploadHandler, + defaultApiUploadUrlHandler, + defaultApiAttachmentUrlHandler, + defaultApiSubmitHandler, ]; diff --git a/mocks/handlers/api/types.ts b/mocks/handlers/api/types.ts index fda525546..a9ccccd6d 100644 --- a/mocks/handlers/api/types.ts +++ b/mocks/handlers/api/types.ts @@ -4,29 +4,32 @@ import { types, subtypes } from "../../data/types"; type GetTypesBody = { authorityId: number }; type GetSubTypesBody = { authorityId: number; typeIds: number[] }; -const defaultTypeHandler = http.post(/\/getTypes$/, async ({ request }) => { - const { authorityId } = await request.json(); - - const hits = - types.filter( - (type) => - type?._source?.authorityId == authorityId && !type?._source?.name.match(/Do Not Use/), - ) || []; - - return HttpResponse.json({ - hits: { - hits, - }, - }); -}); - -export const errorTypeHandler = http.post( - /\/getTypes$/, +const defaultApiTypeHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/getTypes", + async ({ request }) => { + const { authorityId } = await request.json(); + + const hits = + types.filter( + (type) => + type?._source?.authorityId == authorityId && !type?._source?.name.match(/Do Not Use/), + ) || []; + + return HttpResponse.json({ + hits: { + hits, + }, + }); + }, +); + +export const errorApiTypeHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/getTypes", async () => new HttpResponse("Internal server error", { status: 500 }), ); -const defaultSubTypesHandler = http.post( - /\/getSubTypes$/, +const defaultApiSubTypesHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/getSubTypes", async ({ request }) => { const { authorityId, typeIds } = await request.json(); @@ -46,9 +49,9 @@ const defaultSubTypesHandler = http.post( }, ); -export const errorSubTypesHandler = http.post( - /\/getSubTypes$/, +export const errorApiSubTypesHandler = http.post( + "https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests/getSubTypes", () => new HttpResponse("Internal server error", { status: 500 }), ); -export const typeHandlers = [defaultTypeHandler, defaultSubTypesHandler]; +export const typeHandlers = [defaultApiTypeHandler, defaultApiSubTypesHandler]; diff --git a/mocks/handlers/api/user.ts b/mocks/handlers/api/user.ts index 7047e4f3b..48c07897f 100644 --- a/mocks/handlers/api/user.ts +++ b/mocks/handlers/api/user.ts @@ -1,6 +1,6 @@ import { CognitoUserAttribute } from "amazon-cognito-identity-js"; import { isCmsUser } from "shared-utils"; -import { findUserByUsername, convertUserAttributes } from "../authUtils"; +import { findUserByUsername, convertUserAttributes } from "../auth.utils"; import type { TestUserData } from "../.."; // using `any` type here because the function that this is mocking uses any diff --git a/mocks/handlers/authUtils.ts b/mocks/handlers/auth.utils.ts similarity index 100% rename from mocks/handlers/authUtils.ts rename to mocks/handlers/auth.utils.ts diff --git a/mocks/handlers/aws/cognito.ts b/mocks/handlers/aws/cognito.ts index 969cafea9..a83d392dc 100644 --- a/mocks/handlers/aws/cognito.ts +++ b/mocks/handlers/aws/cognito.ts @@ -15,7 +15,7 @@ import type { AdminGetUserRequestBody, TestUserData, } from "../../index.d"; -import { findUserByUsername } from "../authUtils"; +import { findUserByUsername } from "../auth.utils"; import { APIGatewayEventRequestContext } from "shared-types"; import { userResponses } from "../../data/users"; diff --git a/mocks/handlers/index.ts b/mocks/handlers/index.ts index fe792b7f7..71de8b215 100644 --- a/mocks/handlers/index.ts +++ b/mocks/handlers/index.ts @@ -36,7 +36,7 @@ export { setDefaultReviewer, setDefaultStateSubmitter, setMockUsername, -} from "./authUtils.js"; +} from "./auth.utils"; export * from "./api"; export * from "./aws"; diff --git a/mocks/handlers/opensearch/changelog.ts b/mocks/handlers/opensearch/changelog.ts index 456c3a71b..99537d849 100644 --- a/mocks/handlers/opensearch/changelog.ts +++ b/mocks/handlers/opensearch/changelog.ts @@ -2,9 +2,9 @@ import { http, HttpResponse, PathParams } from "msw"; import { GET_ERROR_ITEM_ID } from "../../data"; import items from "../../data/items"; import { SearchQueryBody, TestChangelogDocument, TestChangelogItemResult } from "../../index.d"; -import { getTermKeys, getTermValues, filterItemsByTerm } from "./util"; +import { getTermKeys, getTermValues, filterItemsByTerm } from "../search.utils"; -const defaultChangelogSearchHandler = http.post( +const defaultOSChangelogSearchHandler = http.post( "https://vpc-opensearchdomain-mock-domain.us-east-1.es.amazonaws.com/test-namespace-changelog/_search", async ({ request }) => { const { query } = await request.json(); @@ -73,4 +73,4 @@ const defaultChangelogSearchHandler = http.post( }, ); -export const changelogSearchHandlers = [defaultChangelogSearchHandler]; +export const changelogSearchHandlers = [defaultOSChangelogSearchHandler]; diff --git a/mocks/handlers/opensearch/cpocs.ts b/mocks/handlers/opensearch/cpocs.ts index 8e603ca86..2a3c34c65 100644 --- a/mocks/handlers/opensearch/cpocs.ts +++ b/mocks/handlers/opensearch/cpocs.ts @@ -1,7 +1,7 @@ import { http, HttpResponse } from "msw"; import { cpocsList } from "../../data/cpocs"; -const defaultCpocSearchHandler = http.post( +const defaultOSCpocSearchHandler = http.post( "https://vpc-opensearchdomain-mock-domain.us-east-1.es.amazonaws.com/test-namespace-cpocs/_search", () => HttpResponse.json({ @@ -24,14 +24,14 @@ const defaultCpocSearchHandler = http.post( }), ); -export const emptyCpocSearchHandler = http.post( +export const emptyOSCpocSearchHandler = http.post( "https://vpc-opensearchdomain-mock-domain.us-east-1.es.amazonaws.com/test-namespace-cpocs/_search", () => new HttpResponse(), ); -export const errorCpocSearchHandler = http.post( +export const errorOSCpocSearchHandler = http.post( "https://vpc-opensearchdomain-mock-domain.us-east-1.es.amazonaws.com/test-namespace-cpocs/_search", () => new HttpResponse("Internal server error", { status: 500 }), ); -export const cpocSearchHandlers = [defaultCpocSearchHandler]; +export const cpocSearchHandlers = [defaultOSCpocSearchHandler]; diff --git a/mocks/handlers/opensearch/index.ts b/mocks/handlers/opensearch/index.ts index 48e8c921e..844c985c1 100644 --- a/mocks/handlers/opensearch/index.ts +++ b/mocks/handlers/opensearch/index.ts @@ -16,7 +16,7 @@ export const opensearchHandlers = [ ...typeSearchHandlers, ]; -export { emptyCpocSearchHandler, errorCpocSearchHandler } from "./cpocs"; +export { emptyOSCpocSearchHandler, errorOSCpocSearchHandler } from "./cpocs"; export { errorCreateIndexHandler, errorUpdateFieldMappingHandler, @@ -24,7 +24,7 @@ export { rateLimitBulkUpdateDataHandler, errorDeleteIndexHandler, } from "./indices"; -export { errorMainMultiDocumentHandler } from "./main"; +export { errorOSMainMultiDocumentHandler } from "./main"; export { errorSecurityRolesMappingHandler } from "./security"; -export { errorSubtypeSearchHandler } from "./subtypes"; -export { errorTypeSearchHandler } from "./types"; +export { errorOSSubtypeSearchHandler } from "./subtypes"; +export { errorOSTypeSearchHandler } from "./types"; diff --git a/mocks/handlers/opensearch/main.ts b/mocks/handlers/opensearch/main.ts index eae507d28..08e529580 100644 --- a/mocks/handlers/opensearch/main.ts +++ b/mocks/handlers/opensearch/main.ts @@ -9,9 +9,9 @@ import { TestMainDocument, GetMultiItemBody, } from "../../index.d"; -import { getTermKeys, filterItemsByTerm, getTermValues } from "./util"; +import { getTermKeys, filterItemsByTerm, getTermValues } from "../search.utils"; -const defaultMainDocumentHandler = http.get( +const defaultOSMainDocumentHandler = http.get( `https://vpc-opensearchdomain-mock-domain.us-east-1.es.amazonaws.com/test-namespace-main/_doc/:id`, async ({ params }) => { const { id } = params; @@ -29,7 +29,7 @@ const defaultMainDocumentHandler = http.get( }, ); -const defaultMainMultiDocumentHandler = http.post( +const defaultOSMainMultiDocumentHandler = http.post( "https://vpc-opensearchdomain-mock-domain.us-east-1.es.amazonaws.com/test-namespace-main/_mget", async ({ request }) => { const { ids } = await request.json(); @@ -42,12 +42,12 @@ const defaultMainMultiDocumentHandler = http.post( }, ); -export const errorMainMultiDocumentHandler = http.post( +export const errorOSMainMultiDocumentHandler = http.post( "https://vpc-opensearchdomain-mock-domain.us-east-1.es.amazonaws.com/test-namespace-main/_mget", () => new HttpResponse("Internal server error", { status: 500 }), ); -const defaultMainSearchHandler = http.post( +const defaultOSMainSearchHandler = http.post( "https://vpc-opensearchdomain-mock-domain.us-east-1.es.amazonaws.com/test-namespace-main/_search", async ({ request }) => { const { query } = await request.json(); @@ -156,7 +156,7 @@ const defaultMainSearchHandler = http.post( ); export const mainSearchHandlers = [ - defaultMainDocumentHandler, - defaultMainMultiDocumentHandler, - defaultMainSearchHandler, + defaultOSMainDocumentHandler, + defaultOSMainMultiDocumentHandler, + defaultOSMainSearchHandler, ]; diff --git a/mocks/handlers/opensearch/subtypes.ts b/mocks/handlers/opensearch/subtypes.ts index 94151831d..983cfbe89 100644 --- a/mocks/handlers/opensearch/subtypes.ts +++ b/mocks/handlers/opensearch/subtypes.ts @@ -1,9 +1,9 @@ import { http, HttpResponse, PathParams } from "msw"; import { subtypes } from "../../data/types"; import { SearchQueryBody } from "../../index.d"; -import { getFilterValueAsNumber, getFilterValueAsNumberArray } from "./util"; +import { getFilterValueAsNumber, getFilterValueAsNumberArray } from "../search.utils"; -const defaultSubtypeSearchHandler = http.post( +const defaultOSSubtypeSearchHandler = http.post( "https://vpc-opensearchdomain-mock-domain.us-east-1.es.amazonaws.com/test-namespace-subtypes/_search", async ({ request }) => { const { query } = await request.json(); @@ -45,9 +45,9 @@ const defaultSubtypeSearchHandler = http.post( }, ); -export const errorSubtypeSearchHandler = http.post( +export const errorOSSubtypeSearchHandler = http.post( "https://vpc-opensearchdomain-mock-domain.us-east-1.es.amazonaws.com/test-namespace-subtypes/_search", () => new HttpResponse("Internal server error", { status: 500 }), ); -export const subtypeSearchHandlers = [defaultSubtypeSearchHandler]; +export const subtypeSearchHandlers = [defaultOSSubtypeSearchHandler]; diff --git a/mocks/handlers/opensearch/types.ts b/mocks/handlers/opensearch/types.ts index 5c298ecd9..8928c2c4b 100644 --- a/mocks/handlers/opensearch/types.ts +++ b/mocks/handlers/opensearch/types.ts @@ -1,9 +1,9 @@ import { http, HttpResponse, PathParams } from "msw"; import { types } from "../../data/types"; import { SearchQueryBody } from "../../index.d"; -import { getFilterValueAsNumber } from "./util"; +import { getFilterValueAsNumber } from "../search.utils"; -const defaultTypeSearchHandler = http.post( +const defaultOSTypeSearchHandler = http.post( "https://vpc-opensearchdomain-mock-domain.us-east-1.es.amazonaws.com/test-namespace-types/_search", async ({ request }) => { const { query } = await request.json(); @@ -42,9 +42,9 @@ const defaultTypeSearchHandler = http.post( }, ); -export const errorTypeSearchHandler = http.post( +export const errorOSTypeSearchHandler = http.post( "https://vpc-opensearchdomain-mock-domain.us-east-1.es.amazonaws.com/test-namespace-types/_search", () => new HttpResponse("Internal server error", { status: 500 }), ); -export const typeSearchHandlers = [defaultTypeSearchHandler]; +export const typeSearchHandlers = [defaultOSTypeSearchHandler]; diff --git a/mocks/handlers/opensearch/util.ts b/mocks/handlers/search.utils.ts similarity index 99% rename from mocks/handlers/opensearch/util.ts rename to mocks/handlers/search.utils.ts index 53ffd55d8..608a7b2e1 100644 --- a/mocks/handlers/opensearch/util.ts +++ b/mocks/handlers/search.utils.ts @@ -1,4 +1,4 @@ -import { QueryContainer, TermQuery, TermsQuery, TestHit } from "../../index.d"; +import { QueryContainer, TermQuery, TermsQuery, TestHit } from ".."; export const getFilterValue = ( query: QueryContainer | QueryContainer[] | undefined, diff --git a/mocks/helpers/index.ts b/mocks/helpers/index.ts index f3ae14d1a..a99e252ff 100644 --- a/mocks/helpers/index.ts +++ b/mocks/helpers/index.ts @@ -1 +1 @@ -export * from "./kafka-test-helpers"; +export * from "./kafka.utils"; diff --git a/mocks/helpers/kafka-test-helpers.ts b/mocks/helpers/kafka.utils.ts similarity index 100% rename from mocks/helpers/kafka-test-helpers.ts rename to mocks/helpers/kafka.utils.ts diff --git a/react-app/.env.test b/react-app/.env.test new file mode 100644 index 000000000..188f9ca37 --- /dev/null +++ b/react-app/.env.test @@ -0,0 +1,14 @@ +VITE_API_REGION="us-east-1" +VITE_API_URL=https://test-domain.execute-api.us-east-1.amazonaws.com/mocked-tests +VITE_NODE_ENV="development" +VITE_COGNITO_REGION=us-east-1 +VITE_COGNITO_IDENTITY_POOL_ID=us-east-1::test-identity-pool-id +VITE_COGNITO_USER_POOL_ID=us-east-1_userPool1 +VITE_COGNITO_USER_POOL_CLIENT_ID=userPoolWebClientId +VITE_COGNITO_USER_POOL_CLIENT_DOMAIN=mocked-tests-login-userPoolWebClientId.auth.us-east-1.amazoncognito.com +VITE_COGNITO_REDIRECT_SIGNIN="http://localhost:5000/" +VITE_COGNITO_REDIRECT_SIGNOUT="http://localhost:5000/" +VITE_IDM_HOME_URL=https://test.home.idm.cms.gov +VITE_GOOGLE_ANALYTICS_GTAG="" +VITE_GOOGLE_ANALYTICS_DISABLE="true" +VITE_LAUNCHDARKLY_CLIENT_ID="6638280397c1bc569aea5f3f" diff --git a/react-app/src/api/getAttachmentUrl.test.ts b/react-app/src/api/getAttachmentUrl.test.ts index 67de816de..7c387e564 100644 --- a/react-app/src/api/getAttachmentUrl.test.ts +++ b/react-app/src/api/getAttachmentUrl.test.ts @@ -1,6 +1,10 @@ import { describe, expect, it } from "vitest"; import { getAttachmentUrl } from "./getAttachmentUrl"; -import { ATTACHMENT_BUCKET_NAME, ATTACHMENT_BUCKET_REGION, errorAttachmentUrlHandler } from "mocks"; +import { + ATTACHMENT_BUCKET_NAME, + ATTACHMENT_BUCKET_REGION, + errorApiAttachmentUrlHandler, +} from "mocks"; import { mockedApiServer as mockedServer } from "mocks/server"; describe("getAttachmentUrl tests", () => { @@ -16,7 +20,7 @@ describe("getAttachmentUrl tests", () => { }); it("should throw an error if the response is 500", async () => { - mockedServer.use(errorAttachmentUrlHandler); + mockedServer.use(errorApiAttachmentUrlHandler); await expect(() => getAttachmentUrl(id, ATTACHMENT_BUCKET_NAME, key, filename), diff --git a/react-app/src/api/itemExists.test.ts b/react-app/src/api/itemExists.test.ts index 1dedd78fe..0cc125abc 100644 --- a/react-app/src/api/itemExists.test.ts +++ b/react-app/src/api/itemExists.test.ts @@ -4,7 +4,7 @@ import { TEST_ITEM_ID, NOT_FOUND_ITEM_ID, NOT_EXISTING_ITEM_ID, - errorItemExistsHandler, + errorApiItemExistsHandler, } from "mocks"; import { mockedApiServer as mockedServer } from "mocks/server"; @@ -25,7 +25,7 @@ describe("itemExists test", () => { }); it("should return false if there is an error getting the item", async () => { - mockedServer.use(errorItemExistsHandler); + mockedServer.use(errorApiItemExistsHandler); const found = await itemExists(TEST_ITEM_ID); expect(found).toBeFalsy(); diff --git a/react-app/src/api/useGetCPOCs.test.ts b/react-app/src/api/useGetCPOCs.test.ts index c576b5f55..60e5f9ff1 100644 --- a/react-app/src/api/useGetCPOCs.test.ts +++ b/react-app/src/api/useGetCPOCs.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "vitest"; import { fetchCpocData } from "./useGetCPOCs"; -import { errorCpocHandler } from "mocks"; +import { errorApiCpocHandler } from "mocks"; import { mockedApiServer as mockedServer } from "mocks/server"; import { cpocsList } from "mocks/data/cpocs"; @@ -12,7 +12,7 @@ describe("useGetCPOCs test", () => { }); it("should handle an error when fetching CPOCs", async () => { - mockedServer.use(errorCpocHandler); + mockedServer.use(errorApiCpocHandler); const result = await fetchCpocData(); expect(result).toBeUndefined(); diff --git a/react-app/src/api/useGetPackageActions.test.ts b/react-app/src/api/useGetPackageActions.test.ts index f2ce5dd78..38fa24615 100644 --- a/react-app/src/api/useGetPackageActions.test.ts +++ b/react-app/src/api/useGetPackageActions.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it, afterEach } from "vitest"; import { getPackageActions } from "./useGetPackageActions"; import { Action } from "shared-types"; import { - errorPackageActionsHandler, + errorApiPackageActionsHandler, WITHDRAW_RAI_ITEM_C, TEST_ITEM_ID, NOT_FOUND_ITEM_ID, @@ -64,7 +64,7 @@ describe("getPackageActions test", () => { }); it("should return 500 if there is a server error", async () => { - mockedServer.use(errorPackageActionsHandler); + mockedServer.use(errorApiPackageActionsHandler); await expect(() => getPackageActions(WITHDRAW_RAI_ITEM_C)).rejects.toThrowError( "Request failed with status code 500", diff --git a/react-app/src/api/useGetTypes.test.ts b/react-app/src/api/useGetTypes.test.ts index dacf6a638..b4b321e03 100644 --- a/react-app/src/api/useGetTypes.test.ts +++ b/react-app/src/api/useGetTypes.test.ts @@ -14,7 +14,7 @@ import { chipTypes, chipSubtypes, } from "mocks/data/types"; -import { errorSubTypesHandler, errorTypeHandler } from "mocks"; +import { errorApiSubTypesHandler, errorApiTypeHandler } from "mocks"; import { mockedApiServer as mockedServer } from "mocks/server"; describe("fetchData", () => { @@ -35,7 +35,7 @@ describe("fetchData", () => { }); it("throws an error when fetch fails", async () => { - mockedServer.use(errorTypeHandler); + mockedServer.use(errorApiTypeHandler); await expect(fetchData({ authorityId: ERROR_AUTHORITY_ID })).rejects.toThrow( "Failed to fetch types", @@ -69,7 +69,7 @@ describe("fetchData", () => { }); it("throws an error when fetch fails", async () => { - mockedServer.use(errorSubTypesHandler); + mockedServer.use(errorApiSubTypesHandler); await expect(fetchData({ authorityId: ERROR_AUTHORITY_ID, typeIds: [] })).rejects.toThrow( "Failed to fetch subtypes", diff --git a/react-app/src/api/useSearch.test.ts b/react-app/src/api/useSearch.test.ts new file mode 100644 index 000000000..c412d53ea --- /dev/null +++ b/react-app/src/api/useSearch.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from "vitest"; +import { getOsData } from "./useSearch"; +import { cpocsList } from "mocks/data/cpocs"; + +describe("getOsData tests", () => { + it("should return cpocs", async () => { + const results = await getOsData({ + index: "cpocs", + sort: { + field: "lastName", + order: "asc", + }, + pagination: { + number: 0, + size: 20, + }, + filters: [], + }); + expect(results.hits.hits).toEqual(cpocsList); + }); +});