diff --git a/src/components/DecisioningEngine/createContextProvider.js b/src/components/DecisioningEngine/createContextProvider.js index cead84294..8c183aa3f 100644 --- a/src/components/DecisioningEngine/createContextProvider.js +++ b/src/components/DecisioningEngine/createContextProvider.js @@ -12,6 +12,7 @@ governing permissions and limitations under the License. import getBrowser from "../../utils/getBrowser"; import parseUrl from "../../utils/parseUrl"; import flattenObject from "../../utils/flattenObject"; +import libraryVersion from "../../constants/libraryVersion"; export default ({ eventRegistry, window }) => { const pageLoadTimestamp = new Date().getTime(); @@ -47,7 +48,9 @@ export default ({ eventRegistry, window }) => { currentMinute: now.getMinutes(), currentMonth: now.getMonth(), currentYear: now.getFullYear(), - pageVisitDuration: currentTimestamp - pageLoadTimestamp + pageVisitDuration: currentTimestamp - pageLoadTimestamp, + "~timestampu": currentTimestamp / 1000, + "~timestampz": now.toISOString() }; }; @@ -74,7 +77,8 @@ export default ({ eventRegistry, window }) => { return { ...coreGlobalContext, ...getTimeContext(), - window: getWindowContext() + window: getWindowContext(), + "~sdkver": libraryVersion }; }; diff --git a/test/unit/specs/components/DecisioningEngine/decisioningContext.sdkVersion.spec.js b/test/unit/specs/components/DecisioningEngine/decisioningContext.sdkVersion.spec.js new file mode 100644 index 000000000..3596e09f8 --- /dev/null +++ b/test/unit/specs/components/DecisioningEngine/decisioningContext.sdkVersion.spec.js @@ -0,0 +1,59 @@ +/* +Copyright 2023 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ +import libraryVersion from "../../../../../src/constants/libraryVersion"; +import { + mockWindow, + setupResponseHandler, + proposition +} from "./contextTestUtils"; + +describe("DecisioningEngine:globalContext:sdkVersion", () => { + let applyResponse; + const currentVersion = libraryVersion; + beforeEach(() => { + applyResponse = jasmine.createSpy(); + }); + + it("satisfies rule based on matched alloy sdk version", () => { + setupResponseHandler(applyResponse, mockWindow({}), { + definition: { + key: "~sdkver", + matcher: "eq", + values: [currentVersion] + }, + type: "matcher" + }); + + expect(applyResponse).toHaveBeenCalledOnceWith( + jasmine.objectContaining({ + propositions: [proposition] + }) + ); + }); + + it("does not satisfy rule due to unmatched dk version", () => { + setupResponseHandler(applyResponse, mockWindow({}), { + definition: { + key: "~sdkver", + matcher: "eq", + values: ["2.18.0-beta.0"] + }, + type: "matcher" + }); + + expect(applyResponse).toHaveBeenCalledOnceWith( + jasmine.objectContaining({ + propositions: [] + }) + ); + }); +}); diff --git a/test/unit/specs/components/DecisioningEngine/decisioningContext.timestamp.spec.js b/test/unit/specs/components/DecisioningEngine/decisioningContext.timestamp.spec.js index d161c374a..3e75c6b2e 100644 --- a/test/unit/specs/components/DecisioningEngine/decisioningContext.timestamp.spec.js +++ b/test/unit/specs/components/DecisioningEngine/decisioningContext.timestamp.spec.js @@ -331,4 +331,37 @@ describe("DecisioningEngine:globalContext:timeContext", () => { }) ); }); + it("satisfies rule based on matched ~timestampu", () => { + setupResponseHandler(applyResponse, mockWindow({}), { + definition: { + key: "~timestampu", + matcher: "eq", + values: [mockedTimestamp.getTime() / 1000] + }, + type: "matcher" + }); + + expect(applyResponse).toHaveBeenCalledOnceWith( + jasmine.objectContaining({ + propositions: [proposition] + }) + ); + }); + + it("satisfies rule based on matched ~timestampz", () => { + setupResponseHandler(applyResponse, mockWindow({}), { + definition: { + key: "~timestampz", + matcher: "eq", + values: [mockedTimestamp.toISOString()] + }, + type: "matcher" + }); + + expect(applyResponse).toHaveBeenCalledOnceWith( + jasmine.objectContaining({ + propositions: [proposition] + }) + ); + }); });