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

Fixed an issue where bottom of page calls would never send when there was a top of page call with renderDecisions set to false. #1092

Merged
merged 2 commits into from
Jan 8, 2024
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
3 changes: 3 additions & 0 deletions src/components/Personalization/createFetchDataHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export default ({
}
mergeQuery(event, personalizationDetails.createQueryDetails());

// This needs to be called before the response so that future sendEvent calls
// can know to wait until this request is complete for pending display notifications.
const handleNotifications = notificationHandler(
personalizationDetails.isRenderDecisions(),
personalizationDetails.isSendDisplayEvent(),
personalizationDetails.getViewName()
);
Expand Down
9 changes: 7 additions & 2 deletions src/components/Personalization/createNotificationHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ governing permissions and limitations under the License.
import { defer } from "../../utils";

export default (collect, renderedPropositions) => {
return (sendDisplayEvent, viewName) => {
if (!sendDisplayEvent) {
return (isRenderDecisions, isSendDisplayEvent, viewName) => {
if (!isRenderDecisions) {
// If we aren't rendering anything, then we don't need to sendDisplayEvents.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

return () => undefined;
}

if (!isSendDisplayEvent) {
const renderedPropositionsDeferred = defer();
renderedPropositions.concat(renderedPropositionsDeferred.promise);
return renderedPropositionsDeferred.resolve;
Expand Down
6 changes: 5 additions & 1 deletion src/components/Personalization/createOnDecisionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export default ({
propositionsToExecute
);

const handleNotifications = notificationHandler(sendDisplayEvent, viewName);
const handleNotifications = notificationHandler(
renderDecisions,
sendDisplayEvent,
viewName
);
render().then(handleNotifications);

return Promise.resolve({
Expand Down
62 changes: 62 additions & 0 deletions test/functional/specs/Personalization/C15325239.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
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 { t } from "testcafe";
import createFixture from "../../helpers/createFixture";
import {
compose,
orgMainConfigMain,
debugEnabled
} from "../../helpers/constants/configParts";
import { TEST_PAGE as TEST_PAGE_URL } from "../../helpers/constants/url";
import createAlloyProxy from "../../helpers/createAlloyProxy";
import createNetworkLogger from "../../helpers/networkLogger";

const config = compose(orgMainConfigMain, debugEnabled);

const networkLogger = createNetworkLogger();
createFixture({
title: "C15325239: Top and bottom of page",
url: `${TEST_PAGE_URL}?test=C15325239`,
requestHooks: [networkLogger.edgeEndpointLogs]
});

test.meta({
ID: "C15325239",
SEVERITY: "P0",
TEST_RUN: "Regression"
});

test("Test C15325239: Multiple top of page calls are supported.", async () => {
const alloy = createAlloyProxy();
await alloy.configure(config);
await alloy.sendEvent({
renderDecisions: true,
type: "decisioning.propositionFetch",
personalization: {
sendDisplayEvent: false
}
});
await alloy.sendEvent({
type: "decisioning.propositionFetch",
personalization: {
decisionScopes: ["foo"],
sendDisplayEvent: false
}
});
await alloy.sendEventAsync({
personalization: {
includeRenderedPropositions: true
}
});

await t.expect(networkLogger.edgeEndpointLogs.count(() => true)).eql(3);
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("Personalization::createNotificationHandler", () => {
});

it("emits a notification immediately", () => {
const handleNotifications = notificationHandler(true, "foo");
const handleNotifications = notificationHandler(true, true, "foo");
handleNotifications(NOTIFICATIONS);
expect(collect).toHaveBeenCalledOnceWith({
decisionsMeta: NOTIFICATIONS,
Expand All @@ -39,10 +39,15 @@ describe("Personalization::createNotificationHandler", () => {
});

it("defers the notification", () => {
const handleNotifications = notificationHandler(false, "foo");
const handleNotifications = notificationHandler(true, false, undefined);
handleNotifications(NOTIFICATIONS);

expect(collect).not.toHaveBeenCalled();
expect(renderedPropositions.concat).toHaveBeenCalledTimes(1);
});

it("doesn't do anything if renderDecisions is false", () => {
notificationHandler(false, true, undefined);
expect(renderedPropositions.concat).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ describe("Personalization::utils::createAsyncArray", () => {

it("should add items to the array, and clear the items", async () => {
const asyncArray = createAsyncArray();
await asyncArray.concat(Promise.resolve(["myitem1"]));
asyncArray.concat(Promise.resolve(["myitem1"]));
expect(await asyncArray.clear()).toEqual(["myitem1"]);
expect(await asyncArray.clear()).toEqual([]);
});

it("should add multiple arrays", async () => {
const asyncArray = createAsyncArray();
await asyncArray.concat(Promise.resolve(["myitem1"]));
await asyncArray.concat(Promise.resolve(["myitem2"]));
asyncArray.concat(Promise.resolve(["myitem1"]));
asyncArray.concat(Promise.resolve(["myitem2"]));
expect(await asyncArray.clear()).toEqual(["myitem1", "myitem2"]);
});

Expand All @@ -43,4 +43,11 @@ describe("Personalization::utils::createAsyncArray", () => {
deferred.resolve(["myitem1"]);
expect(await clearPromise).toEqual(["myitem1"]);
});

it("should handle rejected promises", async () => {
const asyncArray = createAsyncArray();
asyncArray.concat(Promise.resolve([1, 2]));
asyncArray.concat(Promise.reject(new Error("Error!")));
expect(await asyncArray.clear()).toEqual([1, 2]);
});
});
Loading