Skip to content

Commit

Permalink
Merge branch 'main' into dashboard-sort
Browse files Browse the repository at this point in the history
  • Loading branch information
tbolt committed Jan 10, 2025
2 parents f60cc17 + d2df3ee commit 6022c91
Show file tree
Hide file tree
Showing 38 changed files with 64,248 additions and 11,177 deletions.
25 changes: 3 additions & 22 deletions lib/lambda/checkConsumerLag.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, vi, afterEach } from "vitest";
import { describe, it, expect, vi } from "vitest";
import { handler } from "./checkConsumerLag";
import { Context } from "aws-lambda";
import {
Expand All @@ -10,31 +10,12 @@ import {
TEST_MULTIPLE_TOPICS_TOPIC_NAME,
TEST_MISSING_CONSUMER_FUNCTION_NAME,
TEST_MISSING_CONSUMER_TOPIC_NAME,
mockedAdmin,
} from "mocks";

const mockKafkaAdmin = {
connect: vi.fn(),
describeGroups: vi.fn().mockResolvedValue({
groups: [{ state: "Stable" }],
}),
fetchTopicOffsets: vi.fn().mockResolvedValue([{ offset: "100" }]),
fetchOffsets: vi.fn().mockResolvedValue([{ partitions: [{ offset: "100" }] }]),
disconnect: vi.fn(),
};

vi.mock("kafkajs", () => ({
Kafka: vi.fn().mockImplementation(() => ({
admin: vi.fn().mockReturnValue(mockKafkaAdmin),
})),
}));

describe("Lambda Handler", () => {
const callback = vi.fn();

afterEach(() => {
vi.clearAllMocks();
});

it("should handle successful execution with stable and current offsets", async () => {
const event = {
triggers: [
Expand Down Expand Up @@ -113,7 +94,7 @@ describe("Lambda Handler", () => {
brokerString: "broker1,broker2",
};

mockKafkaAdmin.describeGroups.mockRejectedValueOnce(new Error("Kafka admin error"));
mockedAdmin.describeGroups.mockRejectedValueOnce(new Error("Kafka admin error"));

await handler(event, {} as Context, callback);

Expand Down
134 changes: 134 additions & 0 deletions lib/lambda/processEmailsHandlers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
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";

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 ${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);
});
});
Loading

0 comments on commit 6022c91

Please sign in to comment.