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

MWPW-146209 [MILO][MEP] MEP param override does not work if manifest sent by Target and pzn and chosen column not in Target #2119

Merged
merged 14 commits into from
Apr 10, 2024
2 changes: 1 addition & 1 deletion libs/features/personalization/entitlements.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ENTITLEMENT_MAP = {

export const getEntitlementMap = async () => {
const { env, consumerEntitlements } = getConfig();
if (env.name === 'prod') return { ...consumerEntitlements, ...ENTITLEMENT_MAP };
if (env?.name === 'prod') return { ...consumerEntitlements, ...ENTITLEMENT_MAP };
const { default: STAGE_ENTITLEMENTS } = await import('./stage-entitlements.js');
return { ...consumerEntitlements, ...STAGE_ENTITLEMENTS };
};
Expand Down
43 changes: 26 additions & 17 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,22 +482,6 @@ const checkForParamMatch = (paramStr) => {
};

async function getPersonalizationVariant(manifestPath, variantNames = [], variantLabel = null) {
const config = getConfig();
if (config.mep?.override) {
let manifest;
/* c8 ignore start */
config.mep?.override?.split('---').some((item) => {
const pair = item.trim().split('--');
if (pair[0] === manifestPath && pair.length > 1) {
[, manifest] = pair;
return true;
}
return false;
});
/* c8 ignore stop */
if (manifest) return manifest;
}

const variantInfo = variantNames.reduce((acc, name) => {
let nameArr = [name];
if (!name.startsWith(TARGET_EXP_PREFIX)) nameArr = name.split(',');
Expand All @@ -512,6 +496,7 @@ async function getPersonalizationVariant(manifestPath, variantNames = [], varian

let userEntitlements = [];
if (hasEntitlementTag) {
const config = getConfig();
userEntitlements = await config.entitlements();
}

Expand Down Expand Up @@ -601,7 +586,7 @@ export async function getPersConfig(info, override = false) {
config.executionOrder = `${executionOrder['manifest-execution-order']}-${executionOrder['manifest-type']}`;
} else {
// eslint-disable-next-line prefer-destructuring
config.manifestType = infoKeyMap[1];
config.manifestType = infoKeyMap['manifest-type'][1];
config.executionOrder = '1-1';
}

Expand Down Expand Up @@ -680,13 +665,36 @@ export async function runPersonalization(experiment, config) {
};
}

function overridePersonalizationVariant(manifest, config) {
vgoodric marked this conversation as resolved.
Show resolved Hide resolved
const { manifestPath, variantNames } = manifest;
if (!config.mep?.override) return;
let selectedVariant;
config.mep?.override?.split('---').some((item) => {
const pair = item.trim().split('--');
if (pair[0] === manifestPath && pair.length > 1) {
[, selectedVariant] = pair;
return true;
}
return false;
});
if (!selectedVariant) return
vgoodric marked this conversation as resolved.
Show resolved Hide resolved
vgoodric marked this conversation as resolved.
Show resolved Hide resolved
if (variantNames.includes(selectedVariant)) {
manifest.selectedVariantName = selectedVariant;
manifest.selectedVariant = manifest.variants[selectedVariant];
return
vgoodric marked this conversation as resolved.
Show resolved Hide resolved
vgoodric marked this conversation as resolved.
Show resolved Hide resolved
}
vgoodric marked this conversation as resolved.
Show resolved Hide resolved
manifest.selectedVariantName = selectedVariant;
manifest.selectedVariant = manifest.variants[selectedVariant];
}

function compareExecutionOrder(a, b) {
if (a.executionOrder === b.executionOrder) return 0;
return a.executionOrder > b.executionOrder ? 1 : -1;
}

export function cleanAndSortManifestList(manifests) {
const manifestObj = {};
const config = getConfig();
vgoodric marked this conversation as resolved.
Show resolved Hide resolved
manifests.forEach((manifest) => {
if (!manifest?.manifest) return;
if (!manifest.manifestPath) manifest.manifestPath = normalizePath(manifest.manifest);
Expand All @@ -704,6 +712,7 @@ export function cleanAndSortManifestList(manifests) {
} else {
manifestObj[manifest.manifestPath] = manifest;
}
if (config.mep?.override) overridePersonalizationVariant(manifest, config);
});
return Object.values(manifestObj).sort(compareExecutionOrder);
}
Expand Down
2 changes: 1 addition & 1 deletion libs/features/personalization/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function addPillEventListeners(div) {
}

function createPreviewPill(manifests) {
const overlay = createTag('div', { class: 'mep-preview-overlay', style: 'display: none;' });
const overlay = createTag('div', { class: 'mep-preview-overlay static-links', style: 'display: none;' });
document.body.append(overlay);
const div = document.createElement('div');
div.classList.add('mep-hidden');
Expand Down
9 changes: 9 additions & 0 deletions test/features/personalization/personalization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ describe('Functional Test', () => {
assert.calledWith(window.console.log, 'Invalid selector: ', '.bad...selector');
window.console.log.reset();
});

it('should override to param-newoffer=123', async () => {
let config = getConfig();
config.mep = { override: '/path/to/manifest.json--param-newoffer=123' };
await loadManifestAndSetResponse('./mocks/actions/manifestAppendToSection.json');
await applyPers([{ manifestPath: '/path/to/manifest.json' }]);
config = getConfig();
expect(config.experiments[0].selectedVariantName).to.equal('param-newoffer=123');
});
});

describe('matchGlob function', () => {
Expand Down
Loading