Skip to content

Commit

Permalink
MWPW-161191: Checkout cli parameter does not get rendered correctly (#…
Browse files Browse the repository at this point in the history
…3108)

* MWPW-161191:  Checkout cli parameter does not get rendered correctly

* null safe check

* remove line

* unit tests
  • Loading branch information
Axelcureno authored Oct 30, 2024
1 parent edff299 commit 7c6a043
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions libs/blocks/merch/merch.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,23 @@ export async function initService(force = false, attributes = {}) {
fetchCheckoutLinkConfigs.promise = undefined;
}
const { commerce, env: miloEnv, locale: miloLocale } = getConfig();

const extraAttrs = [
'checkout-workflow-step',
'force-tax-exclusive',
'checkout-client-id',
'allow-override',
];

extraAttrs.forEach((attr) => {
const camelCaseAttr = attr.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
// eslint-disable-next-line no-prototype-builtins
if (commerce?.hasOwnProperty(camelCaseAttr)) {
const value = commerce[camelCaseAttr];
delete commerce[camelCaseAttr];
commerce[attr] = value;
}
});
initService.promise = initService.promise ?? polyfills().then(async () => {
await import('../../deps/mas/commerce.js');
const { language, locale } = getMiloLocaleSettings(miloLocale);
Expand Down
2 changes: 1 addition & 1 deletion libs/features/mas/commerce/test/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('getSettings', () => {
});

it('overrides with search parameters', () => {
const checkoutClientId = 'adobecom';
const checkoutClientId = 'adobe_com';
const checkoutWorkflowStep = 'segmentation';
const promotionCode = 'nicopromo';

Expand Down
4 changes: 2 additions & 2 deletions test/blocks/merch/merch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ describe('Merch Block', () => {
it('renders merch link to CTA, config values', async () => {
setConfig({
...config,
commerce: { ...config.commerce },
commerce: { ...config.commerce, checkoutClientId: 'dc' },
});
mockIms();
await initService(true, { 'checkout-client-id': 'dc' });
await initService(true);
const el = await merch(document.querySelector('.merch.cta.config'));
const { dataset, href, nodeName, textContent } = await el.onceSettled();
const url = new URL(href);
Expand Down

0 comments on commit 7c6a043

Please sign in to comment.