From 2853492440fd1ec7ebf884672bb42b520b07cddf Mon Sep 17 00:00:00 2001 From: Marceli Wac Date: Wed, 10 Apr 2024 09:57:19 +0100 Subject: [PATCH] test: Add test to detect incorrectly deserialized messages when using mismatched serializers. Signed-off-by: Marceli Wac --- test/integration/index.spec.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/integration/index.spec.js b/test/integration/index.spec.js index ed23323..798f7b4 100644 --- a/test/integration/index.spec.js +++ b/test/integration/index.spec.js @@ -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()); @@ -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); @@ -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(); + }); }); });