From 7c0011620b905de4aea202b740809b6a71eedb50 Mon Sep 17 00:00:00 2001 From: Jon Snyder Date: Wed, 18 Oct 2023 15:53:37 -0600 Subject: [PATCH] Be explicit about error conditions in DomAction and HtmlContent processors --- .../handlers/createProcessDomAction.js | 6 +++--- .../handlers/createProcessHtmlContent.js | 4 ++-- .../handlers/createProcessDomAction.spec.js | 20 +++++++++++++++---- .../handlers/createProcessHtmlContent.spec.js | 20 +++++++++++++++---- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/components/Personalization/handlers/createProcessDomAction.js b/src/components/Personalization/handlers/createProcessDomAction.js index dd825a16b..1d76448c6 100644 --- a/src/components/Personalization/handlers/createProcessDomAction.js +++ b/src/components/Personalization/handlers/createProcessDomAction.js @@ -14,13 +14,13 @@ export default ({ modules, logger, storeClickMetrics }) => item => { if (!type) { logger.warn("Invalid DOM action data: missing type.", item.getData()); - return {}; + return { setRenderAttempted: false, includeInNotification: false }; } if (type === "click") { if (!selector) { logger.warn("Invalid DOM action data: missing selector.", item.getData()); - return {}; + return { setRenderAttempted: false, includeInNotification: false }; } storeClickMetrics({ selector, meta: item.getMeta() }); return { setRenderAttempted: true, includeInNotification: false }; @@ -28,7 +28,7 @@ export default ({ modules, logger, storeClickMetrics }) => item => { if (!modules[type]) { logger.warn("Invalid DOM action data: unknown type.", item.getData()); - return {}; + return { setRenderAttempted: false, includeInNotification: false }; } return { diff --git a/src/components/Personalization/handlers/createProcessHtmlContent.js b/src/components/Personalization/handlers/createProcessHtmlContent.js index a19fcba2f..15ca07255 100644 --- a/src/components/Personalization/handlers/createProcessHtmlContent.js +++ b/src/components/Personalization/handlers/createProcessHtmlContent.js @@ -13,12 +13,12 @@ export default ({ modules, logger }) => item => { const { type, selector } = item.getData() || {}; if (!selector || !type) { - return {}; + return { setRenderAttempted: false, includeInNotification: false }; } if (!modules[type]) { logger.warn("Invalid HTML content data", item.getData()); - return {}; + return { setRenderAttempted: false, includeInNotification: false }; } return { diff --git a/test/unit/specs/components/Personalization/handlers/createProcessDomAction.spec.js b/test/unit/specs/components/Personalization/handlers/createProcessDomAction.spec.js index ffaaa2170..9c786b061 100644 --- a/test/unit/specs/components/Personalization/handlers/createProcessDomAction.spec.js +++ b/test/unit/specs/components/Personalization/handlers/createProcessDomAction.spec.js @@ -34,7 +34,10 @@ describe("createProcessDomAction", () => { it("returns an empty object if the item has no data, and logs missing type", () => { data = undefined; - expect(processDomAction(item)).toEqual({}); + expect(processDomAction(item)).toEqual({ + setRenderAttempted: false, + includeInNotification: false + }); expect(logger.warn).toHaveBeenCalledWith( "Invalid DOM action data: missing type.", undefined @@ -43,7 +46,10 @@ describe("createProcessDomAction", () => { it("returns an empty object if the item has no type, and logs missing type", () => { data = {}; - expect(processDomAction(item)).toEqual({}); + expect(processDomAction(item)).toEqual({ + setRenderAttempted: false, + includeInNotification: false + }); expect(logger.warn).toHaveBeenCalledWith( "Invalid DOM action data: missing type.", {} @@ -52,7 +58,10 @@ describe("createProcessDomAction", () => { it("returns an empty object if the item has an unknown type, and logs unknown type", () => { data = { type: "typeC" }; - expect(processDomAction(item)).toEqual({}); + expect(processDomAction(item)).toEqual({ + setRenderAttempted: false, + includeInNotification: false + }); expect(logger.warn).toHaveBeenCalledWith( "Invalid DOM action data: unknown type.", { @@ -63,7 +72,10 @@ describe("createProcessDomAction", () => { it("returns an empty object if the item has no selector for a click type, and logs missing selector", () => { data = { type: "click" }; - expect(processDomAction(item)).toEqual({}); + expect(processDomAction(item)).toEqual({ + setRenderAttempted: false, + includeInNotification: false + }); expect(logger.warn).toHaveBeenCalledWith( "Invalid DOM action data: missing selector.", { diff --git a/test/unit/specs/components/Personalization/handlers/createProcessHtmlContent.spec.js b/test/unit/specs/components/Personalization/handlers/createProcessHtmlContent.spec.js index cef24684e..6c757433c 100644 --- a/test/unit/specs/components/Personalization/handlers/createProcessHtmlContent.spec.js +++ b/test/unit/specs/components/Personalization/handlers/createProcessHtmlContent.spec.js @@ -24,25 +24,37 @@ describe("createProcessHtmlContent", () => { it("returns an empty object if the item has no data", () => { data = undefined; - expect(processHtmlContent(item)).toEqual({}); + expect(processHtmlContent(item)).toEqual({ + setRenderAttempted: false, + includeInNotification: false + }); expect(logger.warn).not.toHaveBeenCalled(); }); it("returns an empty object if the item has no type", () => { data = { selector: ".myselector" }; - expect(processHtmlContent(item)).toEqual({}); + expect(processHtmlContent(item)).toEqual({ + setRenderAttempted: false, + includeInNotification: false + }); expect(logger.warn).not.toHaveBeenCalled(); }); it("returns an empty object if the item has no selector", () => { data = { type: "mytype" }; - expect(processHtmlContent(item)).toEqual({}); + expect(processHtmlContent(item)).toEqual({ + setRenderAttempted: false, + includeInNotification: false + }); expect(logger.warn).not.toHaveBeenCalled(); }); it("returns an empty object if the item has an unknown type, and logs unknown type", () => { data = { type: "typeC", selector: ".myselector", content: "mycontent" }; - expect(processHtmlContent(item)).toEqual({}); + expect(processHtmlContent(item)).toEqual({ + setRenderAttempted: false, + includeInNotification: false + }); expect(logger.warn).toHaveBeenCalledWith("Invalid HTML content data", { type: "typeC", selector: ".myselector",