Skip to content

Commit

Permalink
feat(cb2-10603): attempt to decode SQS
Browse files Browse the repository at this point in the history
  • Loading branch information
naathanbrown committed Mar 27, 2024
1 parent 50b03c5 commit f0d99d2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/functions/reportGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const reportGen: Handler = async (event: any, context?: Context, callback?: Call
});
};

const processRecord = (record: any) => {
export const processRecord = (record: any) => {
const recordBody = JSON.parse(JSON.parse(record).Message) ?? "";
if (
recordBody.eventName === "MODIFY"
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/reportGenFunction.unitTest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { reportGen } from "../../src/functions/reportGen";
import mockContext from "aws-lambda-mock-context";
import { ReportGenerationService } from "../../src/services/ReportGenerationService";
import { SendATFReport } from "../../src/services/SendATFReport";
// import mockConfig from "../util/mockConfig";

jest.mock("../../src/services/ReportGenerationService");
jest.mock("../../src/services/SendATFReport");

const mockPayload = "{\n \"Type\" : \"Notification\",\n \"MessageId\" : \"-c9d5---\",\n \"TopicArn\" : \"tf-visit\",\n \"Message\" : \"{\\\"eventID\\\":\\\"f9e63bf29bd6adf174e308201a97259f\\\",\\\"eventName\\\":\\\"MODIFY\\\",\\\"eventVersion\\\":\\\"1.1\\\",\\\"eventSource\\\":\\\"aws:dynamodb\\\",\\\"awsRegion\\\":\\\"eu-west-1\\\",\\\"dynamodb\\\":{\\\"ApproximateCreationDateTime\\\":1711549645,\\\"Keys\\\":{\\\"id\\\":{\\\"S\\\":\\\"6e4bd304-446e-4678-8289-dasdasjkl\\\"}},\\\"NewImage\\\":{\\\"testerStaffId\\\":{\\\"S\\\":\\\"132\\\"},\\\"testStationPNumber\\\":{\\\"S\\\":\\\"87-1369564\\\"},\\\"testerEmail\\\":{\\\"S\\\":\\\"tester@dvsa.gov.uk1111\\\"},\\\"testStationType\\\":{\\\"S\\\":\\\"gvts\\\"},\\\"testStationEmail\\\":{\\\"S\\\":\\\"teststationname@dvsa.gov.uk\\\"},\\\"startTime\\\":{\\\"S\\\":\\\"2022-01-01T10:00:40.561Z\\\"},\\\"endTime\\\":{\\\"S\\\":\\\"2022-01-01T10:00:40.561Z\\\"},\\\"id\\\":{\\\"S\\\":\\\"6e4bd304-446e-4678-8289-dasdasjkl\\\"},\\\"testStationName\\\":{\\\"S\\\":\\\"Rowe, Wunsch and Wisoky\\\"},\\\"activityType\\\":{\\\"S\\\":\\\"visit\\\"},\\\"activityDay\\\":{\\\"S\\\":\\\"2022-01-01\\\"},\\\"testerName\\\":{\\\"S\\\":\\\"namey mcname\\\"}},\\\"OldImage\\\":{\\\"testerStaffId\\\":{\\\"S\\\":\\\"132\\\"},\\\"testStationPNumber\\\":{\\\"S\\\":\\\"87-1369564\\\"},\\\"testerEmail\\\":{\\\"S\\\":\\\"tester@dvsa.gov.uk1111\\\"},\\\"testStationType\\\":{\\\"S\\\":\\\"gvts\\\"},\\\"testStationEmail\\\":{\\\"S\\\":\\\"teststationname@dvsa.gov.uk\\\"},\\\"startTime\\\":{\\\"S\\\":\\\"2022-01-01T10:00:40.561Z\\\"},\\\"endTime\\\":{\\\"S\\\":\\\"2022-01-01T10:00:40.561Z\\\"},\\\"id\\\":{\\\"S\\\":\\\"6e4bd304-446e-4678-8289-dasdasjkl\\\"},\\\"testStationName\\\":{\\\"S\\\":\\\"Rowe, Wunsch and Wisoky\\\"},\\\"activityType\\\":{\\\"S\\\":\\\"visit\\\"},\\\"activityDay\\\":{\\\"S\\\":\\\"2022-01-01\\\"},\\\"testerName\\\":{\\\"S\\\":\\\"231232132\\\"}},\\\"SequenceNumber\\\":\\\"1234\\\",\\\"SizeBytes\\\":704,\\\"StreamViewType\\\":\\\"NEW_AND_OLD_IMAGES\\\"},\\\"eventSourceARN\\\":\\\"arn:aws::eu--1::/cvs---//:32:37.491\\\"}\",\n \"Timestamp\" : \"2024-03-27T14:27:25.926Z\",\n \"SignatureVersion\" : \"1\",\n \"Signature\" : \"+/+/+3//+//2f3y0TI+/+//---\"\n}";

describe("Retro Gen Function", () => {
beforeAll(() => jest.setTimeout(60000));
afterAll(() => {
Expand Down Expand Up @@ -77,9 +78,8 @@ describe("Retro Gen Function", () => {
it("Should throw an error (generateATFReport fails)", async () => {
ReportGenerationService.prototype.generateATFReport = jest.fn().mockRejectedValue(new Error("Oh no!"));
expect.assertions(1);
// sandbox.stub(ReportGenerationService.prototype, "generateATFReport").throws(new Error("Oh no!"));
try {
await reportGen({ Records: [{ body: true }] }, ctx as any, () => {
await reportGen({ Records: [mockPayload] }, ctx as any, () => {
return;
});
} catch (e) {
Expand All @@ -91,7 +91,7 @@ describe("Retro Gen Function", () => {
SendATFReport.prototype.sendATFReport = jest.fn().mockRejectedValue(new Error("Oh dear"));
expect.assertions(1);
try {
await reportGen({ Records: [{ body: true }] }, ctx as any, () => {
await reportGen({ Records: [mockPayload] }, ctx as any, () => {
return;
});
} catch (e) {
Expand Down

0 comments on commit f0d99d2

Please sign in to comment.