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

feat(test)-submit lambda #987

Merged
merged 8 commits into from
Jan 8, 2025
Merged
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
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(11);
expect(body?.hits?.hits?.length).toEqual(12);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new object that gets pulled into the search

});

it("should handle errors during processing", async () => {
Expand Down
257 changes: 257 additions & 0 deletions lib/lambda/submit/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
import { submit } from "./index";
import { APIGatewayEvent } from "node_modules/shared-types";
import { describe, it, expect, vi, afterEach, beforeEach } from "vitest";
import { getRequestContext } from "mocks";
import {
capitatedAmendmentBase,
appkBase,
capitatedInitial,
capitatedRenewal,
contractingAmmendment,
contractingInitial,
contractingRenewal,
newChipSubmission,
newMedicaidSubmission,
respondToRai,
temporaryExtension,
toggleWithdrawRai,
uploadSubsequentDocuments,
withdrawPackage,
withdrawRai,
} from "mocks/data/submit/base";

vi.mock("kafkajs", () => {
const producer = {
connect: vi.fn(),
send: vi.fn(),
disconnect: vi.fn(),
};
const kafka = {
producer: () => producer,
};
return {
Kafka: vi.fn(() => kafka),
Producer: vi.fn(() => producer),
};
});
describe("submit Lambda function", () => {
let brokerString: string | undefined;
beforeEach(() => {
brokerString = process.env.brokerString;
process.env.brokerString = "broker1,broker2";
});

afterEach(() => {
process.env.brokerString = brokerString;
});
it("should have no body", async () => {
const event = {} as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(400);
expect(result.body).toEqual('"Event body required"');
});
it("should have no event in the body", async () => {
const event = {
body: `{"event": ""}`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use JSON.stringify() here, I think that's what the other tests are doing for event bodies

} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(400);
expect(result.body).toEqual('{"message":"Bad Request - Missing event name in body"}');
});

it("should have a bad event in the body", async () => {
const event = {
body: `{"event": "Not a real event"}`,
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(400);
expect(result.body).toEqual('{"message":"Bad Request - Unknown event type Not a real event"}');
});
it("should start to create an capitated ammendment event", async () => {
const base = JSON.stringify(capitatedAmendmentBase);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an capitated ammendment event", async () => {
const base = JSON.stringify(capitatedAmendmentBase);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an app-k event", async () => {
const base = JSON.stringify(appkBase);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an capitated initial event", async () => {
const base = JSON.stringify(capitatedInitial);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an contracting ammendment event", async () => {
const base = JSON.stringify(contractingAmmendment);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an contracting initial event", async () => {
const base = JSON.stringify(contractingInitial);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an contracting renewal event", async () => {
const base = JSON.stringify(contractingRenewal);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an new chip submission event", async () => {
const base = JSON.stringify(newChipSubmission);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an new chip medicaid submission event", async () => {
const base = JSON.stringify(newMedicaidSubmission);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an new respond to rai event", async () => {
const base = JSON.stringify(respondToRai);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an temporary extension event", async () => {
const base = JSON.stringify(temporaryExtension);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an toggle withdraw event", async () => {
const base = JSON.stringify(toggleWithdrawRai);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an withdraw package event", async () => {
const base = JSON.stringify(withdrawPackage);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an withdraw rai event", async () => {
const base = JSON.stringify(withdrawRai);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an capitated renewal event", async () => {
const base = JSON.stringify(capitatedRenewal);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an contracting initial event", async () => {
const base = JSON.stringify(contractingInitial);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
it("should start to create an upload subsequent documents event", async () => {
const base = JSON.stringify(uploadSubsequentDocuments);

const event = {
body: base,
requestContext: getRequestContext(),
} as unknown as APIGatewayEvent;
const result = await submit(event);
expect(result.statusCode).toEqual(200);
expect(result.body).toEqual('{"message":"success"}');
});
});
Loading
Loading