Skip to content

Commit

Permalink
stash commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvatadobe committed Nov 5, 2024
1 parent 1e061e6 commit 5299e9c
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 10 deletions.
19 changes: 12 additions & 7 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,15 +758,16 @@ async function getPersonalizationVariant(manifestPath, variantNames = [], varian
}

const hasMatch = (name) => {
if (name === '') return true;
if (!name) return true;
if (name === variantLabel?.toLowerCase()) return true;
if (name.startsWith('param-')) return checkForParamMatch(name);
if (userEntitlements?.includes(name)) return true;
return PERSONALIZATION_KEYS.includes(name) && PERSONALIZATION_TAGS[name]();
};

const matchVariant = (name) => {
const matchVariant = (n) => {
// split before checks
const name = n.includes(':') ? n.split(':')[1] : n;
if (name.startsWith(TARGET_EXP_PREFIX)) return hasMatch(name);
const processedList = name.split('&').map((condition) => {
const reverse = condition.trim().startsWith(COLUMN_NOT_OPERATOR);
Expand Down Expand Up @@ -942,7 +943,7 @@ function compareExecutionOrder(a, b) {
return a.executionOrder > b.executionOrder ? 1 : -1;
}

export function cleanAndSortManifestList(manifests) {
export function cleanAndSortManifestList(manifests) {
const config = getConfig();
const manifestObj = {};
let allManifests = manifests;
Expand Down Expand Up @@ -1052,11 +1053,15 @@ export async function applyPers(manifests) {
if (!pznList.length) return;

const pznVariants = pznList.map((r) => {
// accounts for target prefix, but not the nickname character :
let val = r.experiment.selectedVariantName.replace(TARGET_EXP_PREFIX, '').trim().slice(0, 15);
if (val.includes(':')) val = val.split(':')[0].trim();
return val === 'default' ? 'nopzn' : val;
const val = r.experiment.selectedVariantName.replace(TARGET_EXP_PREFIX, '').trim().slice(0, 15);
const arr = val.split(':');
if (arr.length > 2 || arr[0]?.trim() === '' || arr[1]?.trim() === '') {
log('MEP Error: When using (optional) column nicknames, please use the following syntax: "<nickname>: <original audience>"');
}
if (!val.includes(':') || val.startsWith(':')) return val === 'default' ? 'nopzn' : val;
return arr[0].trim();
});

const pznManifests = pznList.map((r) => {
const val = r.experiment?.manifestOverrideName || r.experiment?.manifest;
return getFileName(val).replace('.json', '').trim().slice(0, 15);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"action":"replaceContent",
"selector":"#notthere",
"page filter (optional)":"",
"chrome & loggedout":"https://main--milo--adobecom.hlx.page/drafts/vgoodrich/fragments/139173-mep-and/android"
"my nickname: chrome & loggedout":"https://main--milo--adobecom.hlx.page/drafts/vgoodrich/fragments/139173-mep-and/android"
}
]
},
Expand Down
53 changes: 53 additions & 0 deletions test/features/personalization/mocks/manifestWithNicknames.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"info": {
"total": 3,
"offset": 0,
"limit": 3,
"data": [
{
"key": "manifest-type",
"value": "Personalization"
},
{
"key": "manifest-override-name",
"value": ""
},
{
"key": "manifest-execution-order",
"value": "Normal"
}
]
},
"experiences": {
"total": 1,
"offset": 0,
"limit": 1,
"data": [
{
"action": "replace",
"selector": "any-header",
"page filter (optional)": "",
"target-var1": "target-var1",
"challenger 2: target-var2": "challenger 2: target-var2",
"param-nickname=false": "param-nickname=false",
"pzn2: param-nickname=true": "pzn2: param-nickname=true",
"pzn2: param-nickname=double:": "pzn2: param-nickname=double:",
"param-nickname=end:": "param-nickname=end:",
":param-nickname=start": ":param-nickname=start"
}
]
},
"placeholders": {
"total": 0,
"offset": 0,
"limit": 0,
"data": []
},
":version": 3,
":names": [
"experiences",
"info",
"placeholders"
],
":type": "multi-sheet"
}
55 changes: 53 additions & 2 deletions test/features/personalization/personalization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,16 @@ describe('Functional Test', () => {
expect(config.mep?.martech).to.be.undefined;
});

it('should choose chrome & logged out', async () => {





it('should choose chrome & logged out (using nickname)', async () => {
await loadManifestAndSetResponse('./mocks/manifestWithAmpersand.json');
await init(mepSettings);
const config = getConfig();
expect(config.mep?.martech).to.equal('|chrome & logged|ampersand');
expect(config.mep?.martech).to.equal('|my nickname|ampersand');
});

it('should choose not firefox', async () => {
Expand All @@ -166,6 +171,52 @@ describe('Functional Test', () => {
expect(config.mep?.martech).to.equal('|not firefox|not');
});

it('should not error when nickname has multiple colons', async () => {
await loadManifestAndSetResponse('./mocks/manifestWithNicknames.json');
const tempMepSettings = {
mepParam: '/path/to/manifest.json--pzn2: param-nickname=double:',
mepHighlight: false,
mepButton: false,
pzn: '/path/to/manifest.json',
promo: false,
target: false,
};
await init(tempMepSettings);
const config = getConfig();
console.log('test: ', config);
expect(config.mep?.martech).to.equal('|pzn2|manifest');
});

it('should not error when name nickname is empty', async () => {
await loadManifestAndSetResponse('./mocks/manifestWithNicknames.json');
const tempMepSettings = {
mepParam: '/path/to/manifest.json--:param-nickname=start',
mepHighlight: false,
mepButton: false,
pzn: '/path/to/manifest.json',
promo: false,
target: false,
};
await init(tempMepSettings);
const config = getConfig();
expect(config.mep?.martech).to.equal('|:param-nickname|manifest');
});

it('should show nickname instead of original audience when using nicknames syntax', async () => {
await loadManifestAndSetResponse('./mocks/manifestWithNicknames.json');
const tempMepSettings = {
mepParam: '/path/to/manifest.json--pzn2: param-nickname=true',
mepHighlight: false,
mepButton: false,
pzn: '/path/to/manifest.json',
promo: false,
target: false,
};
await init(tempMepSettings);
const config = getConfig();
expect(config.mep?.martech).to.equal('|pzn2|manifest');
});

it('should read and use entitlement data', async () => {
setConfig(getConfig());
const config = getConfig();
Expand Down

0 comments on commit 5299e9c

Please sign in to comment.