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

Release to val #1029

Merged
merged 10 commits into from
Jan 21, 2025
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ jobs:
role-duration-seconds: 10800
- name: Run e2e tests
run: run e2e
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
join_by() { local IFS="$1"; shift; echo "$*"; }
echo "["$(join_by "," "${resourceData[@]}")"]" > "resources/aws-resources.json"
- name: Archive stage resources
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: aws-resources-${{ startsWith(github.ref_name, 'snyk-') && 'snyk' || github.ref_name }}
path: resources/aws-resources.json
Expand Down
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
32 changes: 31 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 All @@ -19,6 +21,19 @@ describe("getPackageActions Handler", () => {
expect(res.statusCode).toEqual(400);
});

it("should return 500 if event body is invalid", async () => {
const event = {
body: {},
requestContext: getRequestContext(),
} as APIGatewayEvent;

const res = await handler(event);

expect(res).toBeTruthy();
expect(res.statusCode).toEqual(500);
expect(res.body).toEqual(JSON.stringify({ message: "Internal server error" }));
});

it("should return 401 if not authorized to view resources from the state", async () => {
const event = {
body: JSON.stringify({ id: HI_TEST_ITEM_ID }),
Expand Down Expand Up @@ -47,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 @@ -60,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
5 changes: 5 additions & 0 deletions lib/lambda/processEmails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ export async function processAndSendEmails(record: any, id: string, config: Proc
const sec = await getSecret(config.emailAddressLookupSecretName);

const item = await os.getItem(config.osDomain, getNamespace("main"), id);
if (!item?.found || !item?._source) {
console.log(`The package was not found for id: ${id}. Doing nothing.`);
return;
}

const cpocEmail = [...getCpocEmail(item)];
const srtEmails = [...getSrtEmails(item)];

Expand Down
Loading
Loading