From f9e5d667f31a9ab82a7d903d30d76805af60028a Mon Sep 17 00:00:00 2001 From: Happy Shandilya Date: Thu, 26 Oct 2023 11:33:14 -0700 Subject: [PATCH] few test (#1067) * few test * few test * few test * fix test --- .../specs/DecisioningEngine/C13348429.js | 197 +++--------------- .../specs/DecisioningEngine/C13405889.js | 196 +++-------------- .../specs/DecisioningEngine/C13419240.js | 171 +-------------- .../DecisioningEngine/index.spec.js | 82 ++++++-- 4 files changed, 131 insertions(+), 515 deletions(-) diff --git a/test/functional/specs/DecisioningEngine/C13348429.js b/test/functional/specs/DecisioningEngine/C13348429.js index 042d45fdd..15ef99828 100644 --- a/test/functional/specs/DecisioningEngine/C13348429.js +++ b/test/functional/specs/DecisioningEngine/C13348429.js @@ -10,6 +10,8 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ import { ClientFunction, t } from "testcafe"; +import uuid from "uuid/v4"; +import fetch from "node-fetch"; import createNetworkLogger from "../../helpers/networkLogger"; import createFixture from "../../helpers/createFixture"; import { TEST_PAGE as TEST_PAGE_URL } from "../../helpers/constants/url"; @@ -18,169 +20,10 @@ import getBaseConfig from "../../helpers/getBaseConfig"; import { compose, debugEnabled } from "../../helpers/constants/configParts"; const networkLogger = createNetworkLogger(); -const organizationId = "4DA0571C5FDC4BF70A495FC2@AdobeOrg"; -const dataStreamId = "7a19c434-6648-48d3-948f-ba0258505d98"; - +const organizationId = "906E3A095DC834230A495FD6@AdobeOrg"; +const dataStreamId = "8cefc5ca-1c2a-479f-88f2-3d42cc302514"; const orgMainConfigMain = getBaseConfig(organizationId, dataStreamId); const config = compose(orgMainConfigMain, debugEnabled); - -const mockResponse = { - requestId: "5a38a9ef-67d7-4f66-8977-c4dc0e0967b6", - handle: [ - { - payload: [ - { - id: "a4486740-0a6d-433a-8b65-bfb3ac20485d", - scope: "mobileapp://com.adobe.aguaAppIos", - scopeDetails: { - decisionProvider: "AJO", - correlationID: "a6b7639b-6606-42af-9679-48eb138632d2", - characteristics: { - eventToken: - "eyJtZXNzYWdlRXhlY3V0aW9uIjp7Im1lc3NhZ2VFeGVjdXRpb25JRCI6Ik5BIiwibWVzc2FnZUlEIjoiYTZiNzYzOWItNjYwNi00MmFmLTk2NzktNDhlYjEzODYzMmQyIiwibWVzc2FnZVB1YmxpY2F0aW9uSUQiOiIzZjQxZGNjNy1mNDE0LTRlMmYtYTdjOS1hMTk4ODdlYzNlNWEiLCJtZXNzYWdlVHlwZSI6Im1hcmtldGluZyIsImNhbXBhaWduSUQiOiIwY2RmMDFkZi02ZmE5LTQ0MjktOGE3My05M2ZiY2U1NTIyYWEiLCJjYW1wYWlnblZlcnNpb25JRCI6ImFiYWVhMThhLTJmNzEtNDZlMy1iZWRmLTUxNzg0YTE4MWJiZiIsImNhbXBhaWduQWN0aW9uSUQiOiIzZmIxMTY1OC1iOTMyLTRlMDktYWIyNy03ZWEyOTc2NzY2YTUifSwibWVzc2FnZVByb2ZpbGUiOnsibWVzc2FnZVByb2ZpbGVJRCI6ImVlY2U5NDNlLWVlNWYtNGMwNC1iZGI1LTQ5YjFhMjViMTNmZSIsImNoYW5uZWwiOnsiX2lkIjoiaHR0cHM6Ly9ucy5hZG9iZS5jb20veGRtL2NoYW5uZWxzL2luQXBwIiwiX3R5cGUiOiJodHRwczovL25zLmFkb2JlLmNvbS94ZG0vY2hhbm5lbC10eXBlcy9pbkFwcCJ9fX0=" - }, - activity: { - id: - "0cdf01df-6fa9-4429-8a73-93fbce5522aa#3fb11658-b932-4e09-ab27-7ea2976766a5" - } - }, - items: [ - { - id: "f5134bfa-381e-4b94-8546-d7023e1f3601", - schema: "https://ns.adobe.com/personalization/ruleset-item", - data: { - version: 1, - rules: [ - { - condition: { - definition: { - conditions: [ - { - definition: { - conditions: [ - { - definition: { - key: "~type", - matcher: "eq", - values: [ - "com.adobe.eventType.generic.track" - ] - }, - type: "matcher" - }, - { - definition: { - key: "~source", - matcher: "eq", - values: [ - "com.adobe.eventSource.requestContent" - ] - }, - type: "matcher" - }, - { - definition: { - key: - "~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek", - matcher: "eq", - values: [2] - }, - type: "matcher" - } - ], - logic: "and" - }, - type: "group" - } - ], - logic: "and" - }, - type: "group" - }, - consequences: [ - { - id: "c46c7d03-eb06-4596-9087-272486cb6c41", - type: "cjmiam", - detail: { - mobileParameters: { - verticalAlign: "center", - dismissAnimation: "top", - verticalInset: 0, - backdropOpacity: 0.75, - gestures: { - swipeUp: "adbinapp://dismiss?interaction=swipeUp", - swipeDown: - "adbinapp://dismiss?interaction=swipeDown", - swipeLeft: - "adbinapp://dismiss?interaction=swipeLeft", - swipeRight: - "adbinapp://dismiss?interaction=swipeRight", - tapBackground: - "adbinapp://dismiss?interaction=tapBackground" - }, - cornerRadius: 15, - horizontalInset: 0, - uiTakeover: true, - horizontalAlign: "center", - displayAnimation: "top", - width: 80, - backdropColor: "#ffa500", - height: 60 - }, - html: - '\n\n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n

Fifty percent off!

One hour only!

\n \n\n', - remoteAssets: [ - "https://media3.giphy.com/media/R7ifMrDG24Uc89TpZH/giphy.gif?cid=ecf05e47ohtez4exx2e0u3x1zko365r8pw6lqw0qtjq32z2h&ep=v1_gifs_search&rid=giphy.gif&ct=g" - ] - } - } - ] - } - ] - } - } - ] - } - ], - type: "personalization:decisions", - eventIndex: 0 - }, - { - payload: [ - { - scope: "Target", - hint: "35", - ttlSeconds: 1800 - }, - { - scope: "AAM", - hint: "9", - ttlSeconds: 1800 - }, - { - scope: "EdgeNetwork", - hint: "or2", - ttlSeconds: 1800 - } - ], - type: "locationHint:result" - }, - { - payload: [ - { - key: "kndctr_4DA0571C5FDC4BF70A495FC2_AdobeOrg_cluster", - value: "or2", - maxAge: 1800, - attrs: { - SameSite: "None" - } - } - ], - type: "state:store" - } - ] -}; - createFixture({ title: "Test C13348429: Verify DOM action using the applyResponse command.", requestHooks: [networkLogger.edgeEndpointLogs], @@ -197,8 +40,34 @@ const getIframeContainer = ClientFunction(() => { const element = document.querySelector("#alloy-messaging-container"); return element ? element.innerHTML : ""; }); +const getAepEdgeResponse = async requestId => { + const requestBody = { + events: [ + { + query: { + personalization: { + surfaces: ["web://alloyio.com/functional-test/testPage.html"] + } + }, + xdm: { + timestamp: new Date().toISOString(), + implementationDetails: {} + } + } + ] + }; + const res = await fetch( + `https://edge.adobedc.net/ee/or2/v1/interact?configId=${dataStreamId}&requestId=${requestId}`, + { + body: JSON.stringify(requestBody), + method: "POST" + } + ); + return res.json(); +}; test("Test C13348429: Verify DOM action using the applyResponse command.", async () => { + const realResponse = await getAepEdgeResponse(uuid()); const alloy = createAlloyProxy(); await alloy.configure(config); await alloy.sendEvent({}); @@ -207,12 +76,10 @@ test("Test C13348429: Verify DOM action using the applyResponse command.", async renderDecisions: true, personalization: { decisionContext: { - "~type": "com.adobe.eventType.generic.track", - "~source": "com.adobe.eventSource.requestContent", - "~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek": 2 + user: "alloytest" } }, - responseBody: mockResponse + responseBody: realResponse }); const containerElement = await getIframeContainer(); await t.expect(containerElement).contains("alloy-content-iframe"); diff --git a/test/functional/specs/DecisioningEngine/C13405889.js b/test/functional/specs/DecisioningEngine/C13405889.js index d04c41efb..5b08feed6 100644 --- a/test/functional/specs/DecisioningEngine/C13405889.js +++ b/test/functional/specs/DecisioningEngine/C13405889.js @@ -10,6 +10,8 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ import { ClientFunction, t } from "testcafe"; +import fetch from "node-fetch"; +import uuid from "uuid/v4"; import createNetworkLogger from "../../helpers/networkLogger"; import createFixture from "../../helpers/createFixture"; import { TEST_PAGE as TEST_PAGE_URL } from "../../helpers/constants/url"; @@ -18,169 +20,11 @@ import getBaseConfig from "../../helpers/getBaseConfig"; import { compose, debugEnabled } from "../../helpers/constants/configParts"; const networkLogger = createNetworkLogger(); -const organizationId = "4DA0571C5FDC4BF70A495FC2@AdobeOrg"; -const dataStreamId = "7a19c434-6648-48d3-948f-ba0258505d98"; - +const organizationId = "906E3A095DC834230A495FD6@AdobeOrg"; +const dataStreamId = "8cefc5ca-1c2a-479f-88f2-3d42cc302514"; const orgMainConfigMain = getBaseConfig(organizationId, dataStreamId); const config = compose(orgMainConfigMain, debugEnabled); -const mockResponse = { - requestId: "5a38a9ef-67d7-4f66-8977-c4dc0e0967b6", - handle: [ - { - payload: [ - { - id: "a4486740-0a6d-433a-8b65-bfb3ac20485d", - scope: "mobileapp://com.adobe.aguaAppIos", - scopeDetails: { - decisionProvider: "AJO", - correlationID: "a6b7639b-6606-42af-9679-48eb138632d2", - characteristics: { - eventToken: - "eyJtZXNzYWdlRXhlY3V0aW9uIjp7Im1lc3NhZ2VFeGVjdXRpb25JRCI6Ik5BIiwibWVzc2FnZUlEIjoiYTZiNzYzOWItNjYwNi00MmFmLTk2NzktNDhlYjEzODYzMmQyIiwibWVzc2FnZVB1YmxpY2F0aW9uSUQiOiIzZjQxZGNjNy1mNDE0LTRlMmYtYTdjOS1hMTk4ODdlYzNlNWEiLCJtZXNzYWdlVHlwZSI6Im1hcmtldGluZyIsImNhbXBhaWduSUQiOiIwY2RmMDFkZi02ZmE5LTQ0MjktOGE3My05M2ZiY2U1NTIyYWEiLCJjYW1wYWlnblZlcnNpb25JRCI6ImFiYWVhMThhLTJmNzEtNDZlMy1iZWRmLTUxNzg0YTE4MWJiZiIsImNhbXBhaWduQWN0aW9uSUQiOiIzZmIxMTY1OC1iOTMyLTRlMDktYWIyNy03ZWEyOTc2NzY2YTUifSwibWVzc2FnZVByb2ZpbGUiOnsibWVzc2FnZVByb2ZpbGVJRCI6ImVlY2U5NDNlLWVlNWYtNGMwNC1iZGI1LTQ5YjFhMjViMTNmZSIsImNoYW5uZWwiOnsiX2lkIjoiaHR0cHM6Ly9ucy5hZG9iZS5jb20veGRtL2NoYW5uZWxzL2luQXBwIiwiX3R5cGUiOiJodHRwczovL25zLmFkb2JlLmNvbS94ZG0vY2hhbm5lbC10eXBlcy9pbkFwcCJ9fX0=" - }, - activity: { - id: - "0cdf01df-6fa9-4429-8a73-93fbce5522aa#3fb11658-b932-4e09-ab27-7ea2976766a5" - } - }, - items: [ - { - id: "f5134bfa-381e-4b94-8546-d7023e1f3601", - schema: "https://ns.adobe.com/personalization/ruleset-item", - data: { - version: 1, - rules: [ - { - condition: { - definition: { - conditions: [ - { - definition: { - conditions: [ - { - definition: { - key: "~type", - matcher: "eq", - values: [ - "com.adobe.eventType.generic.track" - ] - }, - type: "matcher" - }, - { - definition: { - key: "~source", - matcher: "eq", - values: [ - "com.adobe.eventSource.requestContent" - ] - }, - type: "matcher" - }, - { - definition: { - key: - "~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek", - matcher: "eq", - values: [2] - }, - type: "matcher" - } - ], - logic: "and" - }, - type: "group" - } - ], - logic: "and" - }, - type: "group" - }, - consequences: [ - { - id: "c46c7d03-eb06-4596-9087-272486cb6c41", - type: "cjmiam", - detail: { - mobileParameters: { - verticalAlign: "center", - dismissAnimation: "top", - verticalInset: 0, - backdropOpacity: 0.75, - gestures: { - swipeUp: "adbinapp://dismiss?interaction=swipeUp", - swipeDown: - "adbinapp://dismiss?interaction=swipeDown", - swipeLeft: - "adbinapp://dismiss?interaction=swipeLeft", - swipeRight: - "adbinapp://dismiss?interaction=swipeRight", - tapBackground: - "adbinapp://dismiss?interaction=tapBackground" - }, - cornerRadius: 15, - horizontalInset: 0, - uiTakeover: true, - horizontalAlign: "center", - displayAnimation: "top", - width: 80, - backdropColor: "#ffa500", - height: 60 - }, - html: - '\n\n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n

Fifty percent off!

One hour only!

\n \n\n', - remoteAssets: [ - "https://media3.giphy.com/media/R7ifMrDG24Uc89TpZH/giphy.gif?cid=ecf05e47ohtez4exx2e0u3x1zko365r8pw6lqw0qtjq32z2h&ep=v1_gifs_search&rid=giphy.gif&ct=g" - ] - } - } - ] - } - ] - } - } - ] - } - ], - type: "personalization:decisions", - eventIndex: 0 - }, - { - payload: [ - { - scope: "Target", - hint: "35", - ttlSeconds: 1800 - }, - { - scope: "AAM", - hint: "9", - ttlSeconds: 1800 - }, - { - scope: "EdgeNetwork", - hint: "or2", - ttlSeconds: 1800 - } - ], - type: "locationHint:result" - }, - { - payload: [ - { - key: "kndctr_4DA0571C5FDC4BF70A495FC2_AdobeOrg_cluster", - value: "or2", - maxAge: 1800, - attrs: { - SameSite: "None" - } - } - ], - type: "state:store" - } - ] -}; - createFixture({ title: "Test C13405889: Verify DOM action using the evaluateRulesets command", requestHooks: [networkLogger.edgeEndpointLogs], @@ -197,23 +41,47 @@ const getIframeContainer = ClientFunction(() => { const element = document.querySelector("#alloy-messaging-container"); return element ? element.innerHTML : ""; }); +const getAepEdgeResponse = async requestId => { + const requestBody = { + events: [ + { + query: { + personalization: { + surfaces: ["web://alloyio.com/functional-test/testPage.html"] + } + }, + xdm: { + timestamp: new Date().toISOString(), + implementationDetails: {} + } + } + ] + }; + const res = await fetch( + `https://edge.adobedc.net/ee/or2/v1/interact?configId=${dataStreamId}&requestId=${requestId}`, + { + body: JSON.stringify(requestBody), + method: "POST" + } + ); + return res.json(); +}; test("Test C13405889: Verify DOM action using the evaluateRulesets command", async () => { + const realResponse = await getAepEdgeResponse(uuid()); const alloy = createAlloyProxy(); await alloy.configure(config); await alloy.sendEvent({}); await alloy.applyResponse({ renderDecisions: false, - responseBody: mockResponse + responseBody: realResponse }); await alloy.evaluateRulesets({ renderDecisions: true, personalization: { decisionContext: { - "~type": "com.adobe.eventType.generic.track", - "~source": "com.adobe.eventSource.requestContent", - "~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek": 2 + user: "alloy" } } }); diff --git a/test/functional/specs/DecisioningEngine/C13419240.js b/test/functional/specs/DecisioningEngine/C13419240.js index 4020fcdd0..ffa4a851d 100644 --- a/test/functional/specs/DecisioningEngine/C13419240.js +++ b/test/functional/specs/DecisioningEngine/C13419240.js @@ -18,169 +18,12 @@ import getBaseConfig from "../../helpers/getBaseConfig"; import { compose, debugEnabled } from "../../helpers/constants/configParts"; const networkLogger = createNetworkLogger(); -const organizationId = "4DA0571C5FDC4BF70A495FC2@AdobeOrg"; -const dataStreamId = "7a19c434-6648-48d3-948f-ba0258505d98"; +const organizationId = "906E3A095DC834230A495FD6@AdobeOrg"; +const dataStreamId = "8cefc5ca-1c2a-479f-88f2-3d42cc302514"; const orgMainConfigMain = getBaseConfig(organizationId, dataStreamId); const config = compose(orgMainConfigMain, debugEnabled); -const mockResponse = { - requestId: "5a38a9ef-67d7-4f66-8977-c4dc0e0967b6", - handle: [ - { - payload: [ - { - id: "a4486740-0a6d-433a-8b65-bfb3ac20485d", - scope: "mobileapp://com.adobe.aguaAppIos", - scopeDetails: { - decisionProvider: "AJO", - correlationID: "a6b7639b-6606-42af-9679-48eb138632d2", - characteristics: { - eventToken: - "eyJtZXNzYWdlRXhlY3V0aW9uIjp7Im1lc3NhZ2VFeGVjdXRpb25JRCI6Ik5BIiwibWVzc2FnZUlEIjoiYTZiNzYzOWItNjYwNi00MmFmLTk2NzktNDhlYjEzODYzMmQyIiwibWVzc2FnZVB1YmxpY2F0aW9uSUQiOiIzZjQxZGNjNy1mNDE0LTRlMmYtYTdjOS1hMTk4ODdlYzNlNWEiLCJtZXNzYWdlVHlwZSI6Im1hcmtldGluZyIsImNhbXBhaWduSUQiOiIwY2RmMDFkZi02ZmE5LTQ0MjktOGE3My05M2ZiY2U1NTIyYWEiLCJjYW1wYWlnblZlcnNpb25JRCI6ImFiYWVhMThhLTJmNzEtNDZlMy1iZWRmLTUxNzg0YTE4MWJiZiIsImNhbXBhaWduQWN0aW9uSUQiOiIzZmIxMTY1OC1iOTMyLTRlMDktYWIyNy03ZWEyOTc2NzY2YTUifSwibWVzc2FnZVByb2ZpbGUiOnsibWVzc2FnZVByb2ZpbGVJRCI6ImVlY2U5NDNlLWVlNWYtNGMwNC1iZGI1LTQ5YjFhMjViMTNmZSIsImNoYW5uZWwiOnsiX2lkIjoiaHR0cHM6Ly9ucy5hZG9iZS5jb20veGRtL2NoYW5uZWxzL2luQXBwIiwiX3R5cGUiOiJodHRwczovL25zLmFkb2JlLmNvbS94ZG0vY2hhbm5lbC10eXBlcy9pbkFwcCJ9fX0=" - }, - activity: { - id: - "0cdf01df-6fa9-4429-8a73-93fbce5522aa#3fb11658-b932-4e09-ab27-7ea2976766a5" - } - }, - items: [ - { - id: "f5134bfa-381e-4b94-8546-d7023e1f3601", - schema: "https://ns.adobe.com/personalization/ruleset-item", - data: { - version: 1, - rules: [ - { - condition: { - definition: { - conditions: [ - { - definition: { - conditions: [ - { - definition: { - key: "~type", - matcher: "eq", - values: [ - "com.adobe.eventType.generic.track" - ] - }, - type: "matcher" - }, - { - definition: { - key: "~source", - matcher: "eq", - values: [ - "com.adobe.eventSource.requestContent" - ] - }, - type: "matcher" - }, - { - definition: { - key: - "~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek", - matcher: "eq", - values: [2] - }, - type: "matcher" - } - ], - logic: "and" - }, - type: "group" - } - ], - logic: "and" - }, - type: "group" - }, - consequences: [ - { - id: "c46c7d03-eb06-4596-9087-272486cb6c41", - type: "cjmiam", - detail: { - mobileParameters: { - verticalAlign: "center", - dismissAnimation: "top", - verticalInset: 0, - backdropOpacity: 0.75, - gestures: { - swipeUp: "adbinapp://dismiss?interaction=swipeUp", - swipeDown: - "adbinapp://dismiss?interaction=swipeDown", - swipeLeft: - "adbinapp://dismiss?interaction=swipeLeft", - swipeRight: - "adbinapp://dismiss?interaction=swipeRight", - tapBackground: - "adbinapp://dismiss?interaction=tapBackground" - }, - cornerRadius: 15, - horizontalInset: 0, - uiTakeover: true, - horizontalAlign: "center", - displayAnimation: "top", - width: 80, - backdropColor: "#ffa500", - height: 60 - }, - html: - '\n\n \n \n\n \n \n \n \n \n\n \n \n \n \n \n\n \n

Fifty percent off!

One hour only!

\n \n\n', - remoteAssets: [ - "https://media3.giphy.com/media/R7ifMrDG24Uc89TpZH/giphy.gif?cid=ecf05e47ohtez4exx2e0u3x1zko365r8pw6lqw0qtjq32z2h&ep=v1_gifs_search&rid=giphy.gif&ct=g" - ] - } - } - ] - } - ] - } - } - ] - } - ], - type: "personalization:decisions", - eventIndex: 0 - }, - { - payload: [ - { - scope: "Target", - hint: "35", - ttlSeconds: 1800 - }, - { - scope: "AAM", - hint: "9", - ttlSeconds: 1800 - }, - { - scope: "EdgeNetwork", - hint: "or2", - ttlSeconds: 1800 - } - ], - type: "locationHint:result" - }, - { - payload: [ - { - key: "kndctr_4DA0571C5FDC4BF70A495FC2_AdobeOrg_cluster", - value: "or2", - maxAge: 1800, - attrs: { - SameSite: "None" - } - } - ], - type: "state:store" - } - ] -}; - createFixture({ title: "Test C13419240: Verify DOM action using the sendEvent command", requestHooks: [networkLogger.edgeEndpointLogs], @@ -201,20 +44,12 @@ const getIframeContainer = ClientFunction(() => { test("Test C13419240: Verify DOM action using the sendEvent command", async () => { const alloy = createAlloyProxy(); await alloy.configure(config); - await alloy.sendEvent({}); // establish an identity - - await alloy.applyResponse({ - renderDecisions: false, - responseBody: mockResponse - }); await alloy.sendEvent({ renderDecisions: true, personalization: { decisionContext: { - "~type": "com.adobe.eventType.generic.track", - "~source": "com.adobe.eventSource.requestContent", - "~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek": 2 + user: "alloytest" } } }); diff --git a/test/unit/specs/components/DecisioningEngine/index.spec.js b/test/unit/specs/components/DecisioningEngine/index.spec.js index 0d031b660..87a8d1315 100644 --- a/test/unit/specs/components/DecisioningEngine/index.spec.js +++ b/test/unit/specs/components/DecisioningEngine/index.spec.js @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ import createDecisioningEngine from "../../../../../src/components/DecisioningEngine/index"; -import { defer, injectStorage } from "../../../../../src/utils"; +import { defer } from "../../../../../src/utils"; import { mockRulesetResponseWithCondition, proposition @@ -20,27 +20,26 @@ describe("createDecisioningEngine:commands:evaluateRulesets", () => { let mergeData; let mockEvent; let onResponseHandler; - let decisioningEngine; let awaitConsentDeferred; let consent; + let persistentStorage; + let createNamespacedStorage; - beforeEach(async () => { + beforeEach(() => { mergeData = jasmine.createSpy(); awaitConsentDeferred = defer(); consent = jasmine.createSpyObj("consent", { awaitConsent: awaitConsentDeferred.promise }); - const config = { - orgId: "exampleOrgId", - personalizationStorageEnabled: true - }; window.referrer = "https://www.google.com/search?q=adobe+journey+optimizer&oq=adobe+journey+optimizer"; - const createNamespacedStorage = injectStorage(window); - decisioningEngine = createDecisioningEngine({ - config, - createNamespacedStorage, - consent + persistentStorage = jasmine.createSpyObj("persistentStorage", [ + "getItem", + "setItem", + "clear" + ]); + createNamespacedStorage = jasmine.createSpy().and.returnValue({ + persistent: persistentStorage }); mockEvent = { getContent: () => ({}), @@ -48,11 +47,27 @@ describe("createDecisioningEngine:commands:evaluateRulesets", () => { getViewName: () => undefined, mergeData }; - decisioningEngine.lifecycle.onComponentsRegistered(() => {}); - await awaitConsentDeferred.resolve(); }); - it("should run the evaluateRulesets command and satisfy the rule based on global context", () => { + const setUpDecisionEngine = ({ personalizationStorageEnabled }) => { + const config = { + orgId: "exampleOrgId", + personalizationStorageEnabled + }; + const decisioningEngine = createDecisioningEngine({ + config, + createNamespacedStorage, + consent + }); + decisioningEngine.lifecycle.onComponentsRegistered(() => {}); + return decisioningEngine; + }; + + it("should run the evaluateRulesets command and satisfy the rule based on global context", async () => { + const decisioningEngine = setUpDecisionEngine({ + personalizationStorageEnabled: true + }); + await awaitConsentDeferred.resolve(); onResponseHandler = onResponse => { onResponse({ response: mockRulesetResponseWithCondition({ @@ -77,7 +92,11 @@ describe("createDecisioningEngine:commands:evaluateRulesets", () => { }); }); - it("should run the evaluateRulesets command and does not satisfy rule due to unmatched global context", () => { + it("should run the evaluateRulesets command and does not satisfy rule due to unmatched global context", async () => { + const decisioningEngine = setUpDecisionEngine({ + personalizationStorageEnabled: true + }); + await awaitConsentDeferred.resolve(); onResponseHandler = onResponse => { onResponse({ response: mockRulesetResponseWithCondition({ @@ -102,7 +121,11 @@ describe("createDecisioningEngine:commands:evaluateRulesets", () => { }); }); - it("should run the evaluateRulesets command and return propositions with renderDecisions true", () => { + it("should run the evaluateRulesets command and return propositions with renderDecisions true", async () => { + const decisioningEngine = setUpDecisionEngine({ + personalizationStorageEnabled: true + }); + await awaitConsentDeferred.resolve(); onResponseHandler = onResponse => { onResponse({ response: mockRulesetResponseWithCondition({ @@ -127,7 +150,11 @@ describe("createDecisioningEngine:commands:evaluateRulesets", () => { }); }); - it("should run the evaluateRulesets command returns propositions with renderDecisions false", () => { + it("should run the evaluateRulesets command returns propositions with renderDecisions false", async () => { + const decisioningEngine = setUpDecisionEngine({ + personalizationStorageEnabled: true + }); + await awaitConsentDeferred.resolve(); onResponseHandler = onResponse => { onResponse({ response: mockRulesetResponseWithCondition({ @@ -151,4 +178,23 @@ describe("createDecisioningEngine:commands:evaluateRulesets", () => { propositions: [proposition] }); }); + it("should clear the local storage when personalizationStorageEnabled is false", async () => { + setUpDecisionEngine({ personalizationStorageEnabled: false }); + await awaitConsentDeferred.resolve(); + expect(persistentStorage.clear).toHaveBeenCalled(); + }); + + it("should set eventRegistry storage when consent is obtained", async () => { + setUpDecisionEngine({ personalizationStorageEnabled: true }); + await awaitConsentDeferred.resolve(); + await expectAsync(awaitConsentDeferred.promise).toBeResolved(); + expect(persistentStorage.getItem).toHaveBeenCalled(); + }); + + it("should clear the local storage when consent is not obtained", async () => { + setUpDecisionEngine({ personalizationStorageEnabled: true }); + await awaitConsentDeferred.reject(); + await expectAsync(awaitConsentDeferred.promise).toBeRejected(); + expect(persistentStorage.clear).toHaveBeenCalled(); + }); });