Skip to content

Commit

Permalink
feat: add test for invalid JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
asharonbaltazar committed Nov 27, 2024
1 parent b2ff7e6 commit 64b2610
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/lambda/sinkMainProcessors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,33 @@ describe("processIndex", () => {

expect(spiedOnBulkUpdateDataWrapper).toBeCalledWith([], "main");
});

it("handles kafka records with invalid JSON successfully", () => {
const spiedOnBulkUpdateDataWrapper = vi
.spyOn(sinkLib, "bulkUpdateDataWrapper")
.mockImplementation(vi.fn());

const spiedOnLogError = vi.spyOn(sinkLib, "logError").mockImplementation(vi.fn());

processAndIndex(
[
{
topic: "--mako--branch-name--aws.onemac.migration.cdc",
partition: 0,
offset: 0,
timestamp: 1732645041557,
timestampType: "CREATE_TIME",
key: "TUQtMjQtMjMwMA==",
// encoded object missing the closing curly brace --> }
value:
"eyJldmVudCI6ICJuZXctbWVkaWNhaWQtc3VibWlzc2lvbiIsICJhdHRhY2htZW50cyI6IHt9LCAiYXV0aG9yaXR5IjogIk1lZGljYWlkIFNQQSIsICJwcm9wb3NlZEVmZmVjdGl2ZURhdGUiOiAxNzMyNTk3MjAwMDAwLCAiaWQiOiAiTUQtMjQtMjMwMCIsICJvcmlnaW4iOiAibWFrbyIsICJzdWJtaXR0ZXJOYW1lIjogIkdlb3JnZSBIYXJyaXNvbiIsICJzdWJtaXR0ZXJFbWFpbCI6ICJnZW9yZ2VAZXhhbXBsZS5jb20iLCAidGltZXN0YW1wIjogMTczMjY0NTA0MTUyNQ==",
headers: {},
},
],
"aws.onemac.migration.cdc-0",
);

expect(spiedOnBulkUpdateDataWrapper).toBeCalledWith([], "main");
expect(spiedOnLogError).toBeCalled();
});
});

0 comments on commit 64b2610

Please sign in to comment.