Skip to content

Commit

Permalink
Merge branch 'main' into split-spas
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanyvu committed Jan 17, 2025
2 parents 2472b32 + 8181a1c commit 0325b22
Show file tree
Hide file tree
Showing 59 changed files with 1,643 additions and 222 deletions.
9 changes: 8 additions & 1 deletion lib/lambda/getAllForms.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it, vi } from "vitest";
import { getAllForms } from "./getAllForms";
import * as wfv from "libs/webforms";

vi.mock("../libs/webforms", () => ({
webformVersions: {
Expand All @@ -12,7 +13,6 @@ vi.mock("../libs/webforms", () => ({
},
},
}));

describe("getAllForms", () => {
it("should return a response with status code 200 and the mapped webforms", async () => {
const expectedResponse = {
Expand All @@ -27,4 +27,11 @@ describe("getAllForms", () => {
expect(result?.statusCode).toEqual(200);
expect(result?.body).toEqual(JSON.stringify(expectedResponse.body));
});
it("should return a response with status code 200 and the mapped webforms", async () => {
const mockconstant = wfv as { webformVersions: object };
mockconstant.webformVersions = {};

const result = await getAllForms();
expect(result?.statusCode).toEqual(502);
});
});
11 changes: 6 additions & 5 deletions lib/lambda/getAllForms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ export const getAllForms = async () => {
try {
const formsWithVersions = mapWebformsKeys(webformVersions);

if (formsWithVersions) {
return response({
statusCode: 200,
body: formsWithVersions,
});
if (Object.keys(formsWithVersions).length === 0) {
throw new Error("No form Versions available");
}
return response({
statusCode: 200,
body: formsWithVersions,
});
} catch (error: any) {
console.error("Error:", error);
return response({
Expand Down
6 changes: 3 additions & 3 deletions lib/lambda/getCpocs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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;

Expand All @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions lib/lambda/getForm.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { getForm } from "./getForm";
import { webformVersions } from "libs/webforms";

describe("forms handler", () => {
beforeEach(() => {
// Reset mocks before each test
Expand Down Expand Up @@ -48,4 +49,11 @@ describe("forms handler", () => {
expect(result.statusCode).toBe(200);
expect(result.body).toBe("{}");
});
it("returns 502 because the body is invalid json", async () => {
const event = {
body: "kdjfkldjj:[df",
};
const result = await getForm(event as any);
expect(result.statusCode).toBe(502);
});
});
20 changes: 6 additions & 14 deletions lib/lambda/getForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ export const getForm = async (event: APIGatewayEvent) => {
version += getMaxVersion(id);
}

if (id && version) {
const formObj = webformVersions[id][version];
const cleanedForm = convertRegexToString(formObj);
return response({
statusCode: 200,
body: cleanedForm,
});
}
const formObj = webformVersions[id][version];
const cleanedForm = convertRegexToString(formObj);
return response({
statusCode: 200,
body: cleanedForm,
});
} catch (error: any) {
console.error("Error:", error);
return response({
Expand All @@ -57,12 +55,6 @@ export const getForm = async (event: APIGatewayEvent) => {
},
});
}
return response({
statusCode: 500,
body: {
error: "Internal server error",
},
});
};

function getMaxVersion(id: string): string {
Expand Down
19 changes: 18 additions & 1 deletion lib/lambda/getPackageActions.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { APIGatewayEvent } from "aws-lambda";
import { Action } from "shared-types";
import { getRequestContext } from "mocks";
import {
GET_ERROR_ITEM_ID,
HI_TEST_ITEM_ID,
NOT_FOUND_ITEM_ID,
WITHDRAWN_CHANGELOG_ITEM_ID,
INITIAL_RELEASE_APPK_ITEM_ID,
} from "mocks/data/items";
import { describe, expect, it } from "vitest";
import { handler } from "./getPackageActions";
Expand Down Expand Up @@ -60,7 +62,7 @@ describe("getPackageActions Handler", () => {
expect(res.body).toEqual(JSON.stringify({ message: "No record found for the given id" }));
});

it("should return 200 with available actions if authorized and package is found", async () => {
it("should return 200 with available actions if authorized and package is found and has no app-k", async () => {
const event = {
body: JSON.stringify({ id: WITHDRAWN_CHANGELOG_ITEM_ID }),
requestContext: getRequestContext(),
Expand All @@ -73,6 +75,21 @@ describe("getPackageActions Handler", () => {
expect(res.body).toEqual(JSON.stringify({ actions: [] }));
});

it("should return 200 with available actions if authorized and package is found and has app-k", async () => {
const event = {
body: JSON.stringify({ id: INITIAL_RELEASE_APPK_ITEM_ID }),
requestContext: getRequestContext(),
} as APIGatewayEvent;

const res = await handler(event);

expect(res).toBeTruthy();
expect(res.statusCode).toEqual(200);
expect(res.body).toEqual(
JSON.stringify({ actions: [Action.WITHDRAW_PACKAGE, Action.UPLOAD_SUBSEQUENT_DOCUMENTS] }),
);
});

it("should handle errors during processing", async () => {
const event = {
body: JSON.stringify({ id: GET_ERROR_ITEM_ID }),
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda/getSubTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda/getTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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 }),
Expand Down
Loading

0 comments on commit 0325b22

Please sign in to comment.