Skip to content

Commit

Permalink
Merge branch 'main' into fix-lint-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tbolt authored Jan 16, 2025
2 parents 25a058f + 15843f7 commit 7b4a5ec
Show file tree
Hide file tree
Showing 27 changed files with 976 additions and 81 deletions.
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
13 changes: 13 additions & 0 deletions lib/lambda/getPackageActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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
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
158 changes: 147 additions & 11 deletions lib/lambda/processEmailsHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,112 +4,206 @@ import { SESClient } from "@aws-sdk/client-ses";
import { handler } from "./processEmails";
import { KafkaRecord, KafkaEvent } from "shared-types";
import { Authority } from "shared-types";

import { SIMPLE_ID, WITHDRAW_RAI_ITEM_B, WITHDRAW_RAI_ITEM_C } from "mocks";
const nms = "new-medicaid-submission";
const ncs = "new-chip-submission";
const tempExtension = "temp-extension";
const withdrawPackage = "withdraw-package";
const contractingInitial = "contracting-initial";
const capitatedInitial = "capitated-initial";
const withdrawRai = "withdraw-rai";
const respondToRai = "respond-to-rai";

describe("process emails Handler", () => {
it.each([
[`should send an email for ${nms} with ${Authority.MED_SPA}`, Authority.MED_SPA, nms],
[`should send an email for ${nms} with ${Authority.CHIP_SPA}`, Authority.CHIP_SPA, nms],
[`should send an email for ${nms} with ${Authority["1915b"]}`, Authority["1915b"], nms],
[`should send an email for ${nms} with ${Authority["1915c"]}`, Authority["1915c"], nms],
[`should send an email for ${ncs} with ${Authority.MED_SPA}`, Authority.MED_SPA, ncs],
[`should send an email for ${ncs} with ${Authority.CHIP_SPA}`, Authority.CHIP_SPA, ncs],
[`should send an email for ${ncs} with ${Authority["1915b"]}`, Authority["1915b"], ncs],
[`should send an email for ${ncs} with ${Authority["1915c"]}`, Authority["1915c"], ncs],
[
`should send an email for ${respondToRai} with ${Authority.MED_SPA}`,
Authority.MED_SPA,
respondToRai,
SIMPLE_ID,
],
[
`should send an email for ${respondToRai} with ${Authority.CHIP_SPA}`,
Authority.CHIP_SPA,
respondToRai,
SIMPLE_ID,
],
[
`should send an email for ${respondToRai} with ${Authority["1915b"]}`,
Authority["1915b"],
respondToRai,
SIMPLE_ID,
],
[
`should send an email for ${respondToRai} with ${Authority["1915c"]}`,
Authority["1915c"],
respondToRai,
SIMPLE_ID,
],
[
`should send an email for ${nms} with ${Authority.MED_SPA}`,
Authority.MED_SPA,
nms,
SIMPLE_ID,
],
[
`should send an email for ${nms} with ${Authority.CHIP_SPA}`,
Authority.CHIP_SPA,
nms,
SIMPLE_ID,
],
[
`should send an email for ${nms} with ${Authority["1915b"]}`,
Authority["1915b"],
nms,
SIMPLE_ID,
],
[
`should send an email for ${nms} with ${Authority["1915c"]}`,
Authority["1915c"],
nms,
SIMPLE_ID,
],
[
`should send an email for ${ncs} with ${Authority.MED_SPA}`,
Authority.MED_SPA,
ncs,
SIMPLE_ID,
],
[
`should send an email for ${ncs} with ${Authority.CHIP_SPA}`,
Authority.CHIP_SPA,
ncs,
SIMPLE_ID,
],
[
`should send an email for ${ncs} with ${Authority["1915b"]}`,
Authority["1915b"],
ncs,
SIMPLE_ID,
],
[
`should send an email for ${ncs} with ${Authority["1915c"]}`,
Authority["1915c"],
ncs,
SIMPLE_ID,
],
[
`should send an email for ${tempExtension} with ${Authority.MED_SPA}`,
Authority.MED_SPA,
tempExtension,
SIMPLE_ID,
],
[
`should send an email for ${tempExtension} with ${Authority.CHIP_SPA}`,
Authority.CHIP_SPA,
tempExtension,
SIMPLE_ID,
],
[
`should send an email for ${tempExtension} with ${Authority["1915b"]}`,
Authority["1915b"],
tempExtension,
SIMPLE_ID,
],
[
`should send an email for ${tempExtension} with ${Authority["1915c"]}`,
Authority["1915c"],
tempExtension,
SIMPLE_ID,
],
[
`should send an email for ${withdrawPackage} with ${Authority.MED_SPA}`,
Authority.MED_SPA,
withdrawPackage,
SIMPLE_ID,
],
[
`should send an email for ${withdrawPackage} with ${Authority.CHIP_SPA}`,
Authority.CHIP_SPA,
withdrawPackage,
SIMPLE_ID,
],
[
`should send an email for ${withdrawPackage} for ${ncs} with ${Authority["1915b"]}`,
Authority["1915b"],
withdrawPackage,
SIMPLE_ID,
],
[
`should send an email for ${withdrawPackage} with ${Authority["1915c"]}`,
Authority["1915c"],
withdrawPackage,
SIMPLE_ID,
],
[
`should send an email for ${contractingInitial} with ${Authority.MED_SPA}`,
Authority.MED_SPA,
contractingInitial,
SIMPLE_ID,
],
[
`should send an email for ${contractingInitial} with ${Authority.CHIP_SPA}`,
Authority.CHIP_SPA,
contractingInitial,
SIMPLE_ID,
],
[
`should send an email for ${contractingInitial} with ${Authority["1915b"]}`,
Authority["1915b"],
contractingInitial,
SIMPLE_ID,
],
[
`should send an email for ${contractingInitial} with ${Authority["1915c"]}`,
Authority["1915c"],
contractingInitial,
SIMPLE_ID,
],
[
`should send an email for ${capitatedInitial} with ${Authority.MED_SPA}`,
Authority.MED_SPA,
capitatedInitial,
SIMPLE_ID,
],
[
`should send an email for ${capitatedInitial} with ${Authority.CHIP_SPA}`,
Authority.CHIP_SPA,
capitatedInitial,
SIMPLE_ID,
],
[
`should send an email for ${capitatedInitial} with ${Authority["1915b"]}`,
Authority["1915b"],
capitatedInitial,
SIMPLE_ID,
],
[
`should send an email for ${capitatedInitial} with ${Authority["1915c"]}`,
Authority["1915c"],
capitatedInitial,
SIMPLE_ID,
],
])("%s", async (_, auth, eventType) => {
[
`should send an email for ${withdrawRai} with ${Authority["1915b"]}`,
Authority["1915b"],
withdrawRai,
WITHDRAW_RAI_ITEM_B,
],
[
`should send an email for ${withdrawRai} with ${Authority["1915c"]}`,
Authority["1915c"],
withdrawRai,
WITHDRAW_RAI_ITEM_C,
],
])("%s", async (_, auth, eventType, id) => {
const callback = vi.fn();
const secSPY = vi.spyOn(SESClient.prototype, "send");
const mockEvent: KafkaEvent = {
records: {
"mock-topic": [
{
key: Buffer.from("VA").toString("base64"),
key: Buffer.from(id).toString("base64"),
value: Buffer.from(
JSON.stringify({
origin: "mako",
Expand All @@ -132,3 +226,45 @@ describe("process emails Handler", () => {
expect(secSPY).toHaveBeenCalledTimes(2);
});
});
describe("process emails Handler failures", () => {
it.each([
[
`should send an email for ${withdrawRai} with ${Authority["1915b"]} and fail due to not finding it`,
Authority["1915b"],
withdrawRai,
SIMPLE_ID,
],
[
`should send an email for ${withdrawRai} with ${Authority["1915c"]} and fail due to not finding it`,
Authority["1915c"],
withdrawRai,
SIMPLE_ID,
],
])("%s", async (_, auth, eventType, id = SIMPLE_ID) => {
const callback = vi.fn();
const mockEvent: KafkaEvent = {
records: {
"mock-topic": [
{
key: Buffer.from(id).toString("base64"),
value: Buffer.from(
JSON.stringify({
origin: "mako",
event: eventType,
authority: auth,
}),
).toString("base64"),
headers: {},
timestamp: 1732645041557,
offset: "0",
partition: 0,
topic: "mock-topic",
} as unknown as KafkaRecord,
],
},
eventSource: "",
bootstrapServers: "",
};
await expect(() => handler(mockEvent, {} as Context, callback)).rejects.toThrow();
});
});
2 changes: 1 addition & 1 deletion lib/lambda/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("getSearchData Handler", () => {
const body = JSON.parse(res.body);
expect(body).toBeTruthy();
expect(body?.hits?.hits).toBeTruthy();
expect(body?.hits?.hits?.length).toEqual(14);
expect(body?.hits?.hits?.length).toEqual(16);
});

it("should handle errors during processing", async () => {
Expand Down
Loading

0 comments on commit 7b4a5ec

Please sign in to comment.