Skip to content

Commit

Permalink
Merge pull request #1072 from adobe/defaultPersonalizationEnabledFlag
Browse files Browse the repository at this point in the history
defaultPersonalizationEnabled updates
  • Loading branch information
jonsnyder authored Oct 27, 2023
2 parents ed17f1c + 605b2f8 commit f4e5575
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/components/DataCollector/validateUserEventOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default ({ options }) => {
surfaces: arrayOf(string()).uniqueItems(),
sendDisplayEvent: boolean().default(true),
includeRenderedPropositions: boolean().default(false),
requestPersonalization: boolean(),
defaultPersonalizationEnabled: boolean(),
decisionContext: objectOf({})
}).default({ sendDisplayEvent: true }),
datasetId: string(),
Expand Down
18 changes: 10 additions & 8 deletions src/components/Personalization/createPersonalizationDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ export default ({
logger
);

if (
!this.isCacheInitialized() ||
personalization.requestPersonalization
) {
if (this.shouldRequestDefaultPersonalization()) {
addPageWideScope(scopes);
addPageSurface(eventSurfaces, getPageLocation);
}
Expand Down Expand Up @@ -121,13 +118,18 @@ export default ({
return (
this.hasScopes() ||
this.hasSurfaces() ||
personalization.requestPersonalization ||
(!this.isCacheInitialized() &&
personalization.requestPersonalization !== false)
this.shouldRequestDefaultPersonalization()
);
},
shouldUseCachedData() {
return this.hasViewName() && this.isCacheInitialized();
return this.hasViewName() && !this.shouldFetchData();
},
shouldRequestDefaultPersonalization() {
return (
personalization.defaultPersonalizationEnabled ||
(!this.isCacheInitialized() &&
personalization.defaultPersonalizationEnabled !== false)
);
}
};
};
17 changes: 13 additions & 4 deletions src/components/Personalization/createViewCacheManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 { groupBy } from "../../utils";
import { assign, groupBy } from "../../utils";
import defer from "../../utils/defer";
import { DEFAULT_CONTENT_ITEM } from "../../constants/schema";
import { VIEW_SCOPE_TYPE } from "./constants/scopeType";
Expand Down Expand Up @@ -49,9 +49,18 @@ export default ({ createProposition }) => {
const updateCacheDeferred = defer();

cacheUpdateCreatedAtLeastOnce = true;
viewStoragePromise = viewStoragePromise.then(oldViewStorage =>
updateCacheDeferred.promise.catch(() => oldViewStorage)
);

// Additional updates will merge the new view propositions with the old.
// i.e. if there are new "cart" view propositions they will overwrite the
// old "cart" view propositions, but if there are no new "cart" view
// propositions the old "cart" view propositions will remain.
viewStoragePromise = viewStoragePromise.then(oldViewStorage => {
return updateCacheDeferred.promise
.then(newViewStorage => {
return assign({}, oldViewStorage, newViewStorage);
})
.catch(() => oldViewStorage);
});

return {
update(viewPropositions) {
Expand Down
11 changes: 7 additions & 4 deletions test/functional/specs/Personalization/C14317242.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const decisionContent =
'<div id="C28755">Here is an awesome target offer!</div>';

createFixture({
title: "C14317242: requestPersonalization should control fetching VEC offers",
title:
"C14317242: defaultPersonalizationEnabled should control fetching VEC offers",
requestHooks: [networkLogger.edgeEndpointLogs],
url: `${TEST_PAGE_URL}?test=C28755`
});
Expand All @@ -41,16 +42,18 @@ test.meta({
TEST_RUN: "Regression"
});

test("Test C14317242: requestPersonalization should control fetching VEC offers", async () => {
test("Test C14317242: defaultPersonalizationEnabled should control fetching VEC offers", async () => {
const alloy = createAlloyProxy();
await alloy.configure(config);
// Does not fetch offers because requestPersonalization is false.
await alloy.sendEvent({ personalization: { requestPersonalization: false } });
await alloy.sendEvent({
personalization: { defaultPersonalizationEnabled: false }
});
// Fetches offers because the cache has not been initialized.
const result2 = await alloy.sendEvent({});
// Fetches offers because initializePersonalization is true.
const result3 = await alloy.sendEvent({
personalization: { requestPersonalization: true }
personalization: { defaultPersonalizationEnabled: true }
});

await responseStatus(networkLogger.edgeEndpointLogs.requests, 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,36 @@ describe("Personalization::createPersonalizationDetails", () => {

// s - has scopes or surfaces
// i - cache is initialized
// ip - requestPersonalization flag
// dp - defaultPersonalizationEnabled flag
// fetch - should fetch data
[
{ s: false, i: false, ip: false, fetch: false },
{ s: true, i: false, ip: false, fetch: true },
{ s: false, i: true, ip: false, fetch: false },
{ s: true, i: true, ip: false, fetch: true },
{ s: false, i: false, dp: false, fetch: false },
{ s: true, i: false, dp: false, fetch: true },
{ s: false, i: true, dp: false, fetch: false },
{ s: true, i: true, dp: false, fetch: true },

{ s: false, i: false, ip: true, fetch: true },
{ s: true, i: false, ip: true, fetch: true },
{ s: false, i: true, ip: true, fetch: true },
{ s: true, i: true, ip: true, fetch: true },
{ s: false, i: false, dp: true, fetch: true },
{ s: true, i: false, dp: true, fetch: true },
{ s: false, i: true, dp: true, fetch: true },
{ s: true, i: true, dp: true, fetch: true },

{ s: false, i: false, fetch: true },
{ s: true, i: false, fetch: true },
{ s: false, i: true, fetch: false },
{ s: true, i: true, fetch: true }
].forEach(({ s, i, ip, fetch }) => {
].forEach(({ s, i, dp, fetch }) => {
it(`should ${fetch ? "" : "not "}fetch data when ${
s ? "" : "no "
}scopes, the cache is ${
i ? "" : "not "
}initialized, and initializePersonalization is '${ip}'`, () => {
}initialized, and initializePersonalization is '${dp}'`, () => {
const personalizationDetails = createPersonalizationDetails({
getPageLocation,
renderDecisions: true,
decisionScopes: [],
personalization: {
decisionScopes: s ? ["test"] : undefined,
requestPersonalization: ip
defaultPersonalizationEnabled: dp
},
event,
isCacheInitialized: i,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,7 @@ describe("Personalization::createViewCacheManager", () => {
})
]);

expect(await cartViewPromise.then(propsToJSON)).toEqual([
{
scope: "cart",
scopeDetails: {
characteristics: {
scopeType: "view"
}
},
items: [
{
schema: DEFAULT_CONTENT_ITEM
}
]
}
]);

expect(await cartViewPromise).toEqual([propositions[2]]);
expect(await viewCacheManager.getView("about").then(propsToJSON)).toEqual([
{
id: "foo4",
Expand Down

0 comments on commit f4e5575

Please sign in to comment.