Skip to content

Commit

Permalink
TNT-48367 Make SPA view names lowercase (#1027)
Browse files Browse the repository at this point in the history
* TNT-48367 Make SPA view names lowercase
  • Loading branch information
XDex authored Sep 13, 2023
1 parent e1105f1 commit 3fbc4d9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/components/Personalization/createOnClickHandler.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 { isNonEmptyArray } from "../../utils";
import { isNonEmptyArray, isNonEmptyString } from "../../utils";
import { INTERACT } from "./constants/eventType";
import { PropositionEventType } from "./constants/propositionEventType";
import PAGE_WIDE_SCOPE from "../../constants/pageWideScope";
Expand All @@ -35,10 +35,10 @@ export default ({
const xdm = { eventType: INTERACT };
const scope = decisionsMeta[0].scope;

if (scope !== PAGE_WIDE_SCOPE) {
if (isNonEmptyString(scope) && scope !== PAGE_WIDE_SCOPE) {
xdm.web = {
webPageDetails: {
viewName: scope
viewName: scope.toLowerCase()
}
};
}
Expand Down
17 changes: 11 additions & 6 deletions src/components/Personalization/groupDecisions.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 { isNonEmptyArray, includes } from "../../utils";
import { isNonEmptyArray, includes, assign } from "../../utils";
import isPageWideScope from "./utils/isPageWideScope";
import {
DOM_ACTION,
Expand Down Expand Up @@ -74,11 +74,16 @@ const splitDecisions = (decisions, ...schemas) => {
return { matchedDecisions, unmatchedDecisions };
};

const appendScopeDecision = (scopeDecisions, decision) => {
if (!scopeDecisions[decision.scope]) {
scopeDecisions[decision.scope] = [];
const appendViewScopeDecision = (scopeDecisions, decision) => {
if (!decision.scope) {
return;
}
scopeDecisions[decision.scope].push(decision);
// Override view scope to lowercase to fix any casing issues
const viewDecision = assign({}, decision, { scope: decision.scope.toLowerCase() });
if (!scopeDecisions[viewDecision.scope]) {
scopeDecisions[viewDecision.scope] = [];
}
scopeDecisions[viewDecision.scope].push(viewDecision);
};

const isViewScope = scopeDetails =>
Expand All @@ -96,7 +101,7 @@ const extractDecisionsByScope = decisions => {
if (isPageWideScope(decision.scope)) {
pageWideScopeDecisions.push(decision);
} else if (isViewScope(decision.scopeDetails)) {
appendScopeDecision(viewScopeDecisions, decision);
appendViewScopeDecision(viewScopeDecisions, decision);
} else {
nonPageWideScopeDecisions.push(decision);
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/createEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ export default () => {
return shouldSendEvent;
},
getViewName() {
if (!userXdm || !userXdm.web || !userXdm.web.webPageDetails) {
if (!userXdm || !userXdm.web || !userXdm.web.webPageDetails || !userXdm.web.webPageDetails.viewName) {
return undefined;
}

return userXdm.web.webPageDetails.viewName;
return userXdm.web.webPageDetails.viewName.toLowerCase();
},
toJSON() {
if (!isFinalized) {
Expand Down
4 changes: 2 additions & 2 deletions test/functional/specs/Personalization/C6364798.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const simulateViewChangeForNonExistingView = async alloy => {
eventType: "noviewoffers",
web: {
webPageDetails: {
viewName: "noView"
viewName: "noview"
}
}
}
Expand All @@ -249,7 +249,7 @@ const simulateViewChangeForNonExistingView = async alloy => {
.expect(
noViewNotificationRequestBody.events[0].xdm.web.webPageDetails.viewName
)
.eql("noView");
.eql("noview");
await t
// eslint-disable-next-line no-underscore-dangle
.expect(noViewNotificationRequestBody.events[0].xdm._experience)
Expand Down
4 changes: 2 additions & 2 deletions test/functional/specs/Personalization/C782718.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ const simulateViewChangeForNonExistingView = async alloy => {
eventType: "noviewoffers",
web: {
webPageDetails: {
viewName: "noView"
viewName: "noview"
}
}
}
Expand All @@ -246,7 +246,7 @@ const simulateViewChangeForNonExistingView = async alloy => {
.expect(
noViewNotificationRequestBody.events[0].xdm.web.webPageDetails.viewName
)
.eql("noView");
.eql("noview");
await t
// eslint-disable-next-line no-underscore-dangle
.expect(noViewNotificationRequestBody.events[0].xdm._experience)
Expand Down

0 comments on commit 3fbc4d9

Please sign in to comment.