Skip to content

Commit

Permalink
test: Add test to detect incorrectly deserialized messages when using…
Browse files Browse the repository at this point in the history
… mismatched serializers.

Signed-off-by: Marceli Wac <[email protected]>
  • Loading branch information
marceliwac committed Apr 10, 2024
1 parent 0dcd985 commit 2853492
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/integration/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,8 @@ describe("Integration tests", () => {

beforeEach(() => {
mockLogger.mockReset()
jsonTopicHandler.mockReset()
msgPackTopicHandler.mockReset()
});
beforeAll(() => broker.start().delay(DELAY_AFTER_BROKER_START));
afterAll(() => broker.stop());
Expand All @@ -1073,7 +1075,6 @@ describe("Integration tests", () => {
});

it("should support multiple serializers", async () => {
// This works (as intended)
await broker.sendFromJsonAdapter("test.json", jsonAdapterMsg);
await broker.sendFromMsgPackAdapter("test.msgPack", msgPackAdapterMsg);
await broker.Promise.delay(500);
Expand All @@ -1088,6 +1089,18 @@ describe("Integration tests", () => {
expect(broker.jsonAdapter).toBeDefined();
expect(broker.msgPackAdapter).toBeDefined();
});

it("should not call the handler if the serializers are mismatched", async () => {
// This deserializes without error, but to a wrong data (coincidentally, despite the serializer mismatch)
await broker.sendFromJsonAdapter("test.msgPack", jsonAdapterMsg);
await broker.Promise.delay(500);

// ---- ˇ ASSERT ˇ ---
expect(msgPackTopicHandler).toHaveBeenCalledTimes(1);
expect(msgPackTopicHandler).toHaveBeenCalledWith(jsonAdapterMsg, expect.anything())

expect(broker.msgPackAdapter).toBeDefined();
});
});
});

Expand Down

0 comments on commit 2853492

Please sign in to comment.