Skip to content

Commit

Permalink
Fixed an issue where rendered propositions were not included in displ…
Browse files Browse the repository at this point in the history
…ay notifications. (#1225)

* Add failing e2e test

* Allow proposition rendering to succeed even if a render fails

* Remove exclusivity from relevant functional test

* Remove unnecessary console.log
  • Loading branch information
carterworks authored Jan 23, 2025
1 parent ebab21e commit 56b1a07
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,20 @@ export default ({ schemaProcessors, logger }) => {
});
};

const renderItems = (renderers, meta) =>
Promise.all(renderers.map((renderer) => renderer())).then((results) => {
const successes = results.filter((result) => result);
// as long as at least one renderer succeeds, we want to add the notification
// to the display notifications
if (meta && isNonEmptyArray(successes)) {
return { ...meta, items: successes };
}
return undefined;
});
const renderItems = async (renderers, meta) => {
const results = await Promise.allSettled(
renderers.map((renderer) => renderer()),
);
const successes = results
.filter((result) => result.status === "fulfilled")
.map((result) => result.value);
// as long as at least one renderer succeeds, we want to add the notification
// to the display notifications
if (meta && isNonEmptyArray(successes)) {
return { ...meta, items: successes };
}
return undefined;
};

const processItem = (item) => {
const processor = schemaProcessors[item.getSchema()];
Expand Down
56 changes: 56 additions & 0 deletions test/functional/specs/Personalization/C17409728.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,59 @@ test("Test C17409728: Automatically sends interact event when using applyProposi
// )
// .eql(itemId);
});

test("Test C17409728: Includes rendered propositions as display notifications in sendEvent after using applyPropositions", async () => {
const alloy = createAlloyProxy();
await alloy.configure(compose(getBaseConfig(), debugEnabled));

const propositions = [
{
id: "AT:eyJhY3Rpdml0eUlkIjoiNDQyMzU4IiwiZXhwZXJpZW5jZUlkIjoiIn1=",
scope: "alloy-test-scope-1",
scopeDetails: { decisionProvider: "TGT" },
items: [
{
id: "442359",
schema: "https://ns.adobe.com/personalization/html-content-item",
data: {
content: "<p>Some custom content for the home page</p>",
format: "text/html",
id: "1202448",
},
},
],
},
];
const metadata = {
"alloy-test-scope-1": {
selector: "#home-item1",
actionType: "setHtml",
},
};
const applyPropositionsResult = await alloy.applyPropositions({
propositions,
metadata,
});

const allPropositionsWereRendered =
applyPropositionsResult.propositions.every((p) => p.renderAttempted);
await t.expect(allPropositionsWereRendered).eql(true);
await t.expect(applyPropositionsResult.propositions.length).eql(1);

await alloy.sendEvent({
personalization: { includeRenderedPropositions: true },
});
await t.expect(edgeEndpointLogs.requests.length).eql(1);
const sendEventRequest = edgeEndpointLogs.requests.at(-1);
const sendEventRequestBody = JSON.parse(sendEventRequest.request.body);
const hasTargetDisplayNotifications = sendEventRequestBody.events.some(
({ xdm }) => xdm.eventType === "decisioning.propositionDisplay",
);
const hasPlatformDisplayNotifications = sendEventRequestBody.events.some(
({ xdm }) =>
xdm._experience?.decisioning?.propositionEventType?.display === 1,
);
await t
.expect(hasTargetDisplayNotifications || hasPlatformDisplayNotifications)
.eql(true);
});

0 comments on commit 56b1a07

Please sign in to comment.