Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support "~timestampu" and "~timestampz" #1044

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/DecisioningEngine/createContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
};
};

Expand All @@ -74,7 +77,8 @@ export default ({ eventRegistry, window }) => {
return {
...coreGlobalContext,
...getTimeContext(),
window: getWindowContext()
window: getWindowContext(),
"~sdkver": libraryVersion
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guessing this test will fail every time the SDK version is updated. I suggest mocking it instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing above with real libraryVersion, that will always match.
This one is false test case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 ah that what i get for not reading it closely enough.

},
type: "matcher"
});

expect(applyResponse).toHaveBeenCalledOnceWith(
jasmine.objectContaining({
propositions: []
})
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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]
})
);
});
});