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

Proceess email handler test #1018

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions lib/lambda/processEmailHandler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { describe, it, expect, vi } from "vitest";
import { Context } from "aws-lambda";
import { SESClient } from "@aws-sdk/client-ses";
import { handler } from "./processEmails";
import { KafkaRecord, KafkaEvent } from "shared-types";
import { Authority } from "shared-types";

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 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 ${respondToRai} with ${Authority.MED_SPA}`,
Authority.MED_SPA,
respondToRai,
],
[
`should send an email for ${respondToRai} with ${Authority.CHIP_SPA}`,
Authority.CHIP_SPA,
respondToRai,
],
[
`should send an email for ${respondToRai} with ${Authority["1915b"]}`,
Authority["1915b"],
respondToRai,
],
[
`should send an email for ${respondToRai} with ${Authority["1915c"]}`,
Authority["1915c"],
respondToRai,
],
[`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 ${tempExtension} with ${Authority.MED_SPA}`,
Authority.MED_SPA,
tempExtension,
],
[
`should send an email for ${tempExtension} with ${Authority.CHIP_SPA}`,
Authority.CHIP_SPA,
tempExtension,
],
[
`should send an email for ${tempExtension} with ${Authority["1915b"]}`,
Authority["1915b"],
tempExtension,
],
[
`should send an email for ${tempExtension} with ${Authority["1915c"]}`,
Authority["1915c"],
tempExtension,
],
[
`should send an email for ${withdrawPackage} with ${Authority.MED_SPA}`,
Authority.MED_SPA,
withdrawPackage,
],
[
`should send an email for ${withdrawPackage} with ${Authority.CHIP_SPA}`,
Authority.CHIP_SPA,
withdrawPackage,
],
[
`should send an email for ${withdrawPackage} for ${ncs} with ${Authority["1915b"]}`,
Authority["1915b"],
withdrawPackage,
],
[
`should send an email for ${withdrawPackage} with ${Authority["1915c"]}`,
Authority["1915c"],
withdrawPackage,
],
[
`should send an email for ${contractingInitial} with ${Authority.MED_SPA}`,
Authority.MED_SPA,
contractingInitial,
],
[
`should send an email for ${contractingInitial} with ${Authority.CHIP_SPA}`,
Authority.CHIP_SPA,
contractingInitial,
],
[
`should send an email for ${contractingInitial} with ${Authority["1915b"]}`,
Authority["1915b"],
contractingInitial,
],
[
`should send an email for ${contractingInitial} with ${Authority["1915c"]}`,
Authority["1915c"],
contractingInitial,
],
[
`should send an email for ${capitatedInitial} with ${Authority.MED_SPA}`,
Authority.MED_SPA,
capitatedInitial,
],
[
`should send an email for ${capitatedInitial} with ${Authority.CHIP_SPA}`,
Authority.CHIP_SPA,
capitatedInitial,
],
[
`should send an email for ${capitatedInitial} with ${Authority["1915b"]}`,
Authority["1915b"],
capitatedInitial,
],
[
`should send an email for ${capitatedInitial} with ${Authority["1915c"]}`,
Authority["1915c"],
capitatedInitial,
],
])("%s", async (_, auth, eventType) => {
const callback = vi.fn();
const secSPY = vi.spyOn(SESClient.prototype, "send");
const mockEvent: KafkaEvent = {
records: {
"mock-topic": [
{
key: Buffer.from("VA").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 handler(mockEvent, {} as Context, callback);
expect(secSPY).toHaveBeenCalledTimes(2);
});
});
2 changes: 1 addition & 1 deletion lib/lambda/processEmails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const handler: Handler<KafkaEvent> = async (event) => {
);

console.log("results: ", JSON.stringify(results, null, 2));

console.log(results);
const failures = results.filter((r) => r.status === "rejected");
if (failures.length > 0) {
console.error("Some records failed:", JSON.stringify(failures, null, 2));
Expand Down
Loading