Skip to content

Commit

Permalink
MWPW-146963: OST to support Annual template (#2431)
Browse files Browse the repository at this point in the history
* consume new ost

* upd to latest

* test ost changes

* support annual merch link

* MWPW-146963: calculate annual of ABM

* fix review comment

* include revert of breaking change
  • Loading branch information
3ch023 authored Jun 10, 2024
1 parent 5522ba3 commit 5dfb72a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
31 changes: 13 additions & 18 deletions libs/blocks/merch/merch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ export const PRICE_TEMPLATE_DISCOUNT = 'discount';
export const PRICE_TEMPLATE_OPTICAL = 'optical';
export const PRICE_TEMPLATE_REGULAR = 'price';
export const PRICE_TEMPLATE_STRIKETHROUGH = 'strikethrough';
export const PRICE_TEMPLATE_ANNUAL = 'annual';
const PRICE_TEMPLATE_MAPPING = new Map([
['priceDiscount', PRICE_TEMPLATE_DISCOUNT],
[PRICE_TEMPLATE_DISCOUNT, PRICE_TEMPLATE_DISCOUNT],
['priceOptical', PRICE_TEMPLATE_OPTICAL],
[PRICE_TEMPLATE_OPTICAL, PRICE_TEMPLATE_OPTICAL],
['priceStrikethrough', PRICE_TEMPLATE_STRIKETHROUGH],
[PRICE_TEMPLATE_STRIKETHROUGH, PRICE_TEMPLATE_STRIKETHROUGH],
['priceAnnual', PRICE_TEMPLATE_ANNUAL],
[PRICE_TEMPLATE_ANNUAL, PRICE_TEMPLATE_ANNUAL],
]);

export const PLACEHOLDER_KEY_DOWNLOAD = 'download';

Expand Down Expand Up @@ -415,24 +426,8 @@ export async function getPriceContext(el, params) {
const displayRecurrence = params.get('term');
const displayTax = params.get('tax');
const forceTaxExclusive = params.get('exclusive');
let template = PRICE_TEMPLATE_REGULAR;
// This mapping also supports legacy OST links
switch (params.get('type')) {
case PRICE_TEMPLATE_DISCOUNT:
case 'priceDiscount':
template = PRICE_TEMPLATE_DISCOUNT;
break;
case PRICE_TEMPLATE_OPTICAL:
case 'priceOptical':
template = PRICE_TEMPLATE_OPTICAL;
break;
case PRICE_TEMPLATE_STRIKETHROUGH:
case 'priceStrikethrough':
template = PRICE_TEMPLATE_STRIKETHROUGH;
break;
default:
break;
}
// The PRICE_TEMPLATE_MAPPING supports legacy OST links
const template = PRICE_TEMPLATE_MAPPING.get(params.get('type')) ?? PRICE_TEMPLATE_REGULAR;
return {
...context,
displayOldPrice,
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/ost/ost.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const IMS_COMMERCE_CLIENT_ID = 'aos_milo_commerce';
const IMS_SCOPE = 'AdobeID,openid';
const IMS_ENV = 'prod';
const IMS_PROD_URL = 'https://auth.services.adobe.com/imslib/imslib.min.js';
const OST_VERSION = '1.14.4';
const OST_VERSION = '1.18.2';
const OST_BASE = `https://www.stage.adobe.com/special/tacocat/ost/lib/${OST_VERSION}`;
const OST_SCRIPT_URL = `${OST_BASE}/index.js`;
const OST_STYLE_URL = `${OST_BASE}/index.css`;
Expand Down
6 changes: 3 additions & 3 deletions libs/deps/commerce.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions test/blocks/merch/merch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import merch, {
PRICE_TEMPLATE_DISCOUNT,
PRICE_TEMPLATE_OPTICAL,
PRICE_TEMPLATE_STRIKETHROUGH,
PRICE_TEMPLATE_ANNUAL,
CHECKOUT_ALLOWED_KEYS,
buildCta,
getCheckoutContext,
Expand All @@ -19,6 +20,7 @@ import merch, {
getModalAction,
getCheckoutAction,
PRICE_LITERALS_URL,
PRICE_TEMPLATE_REGULAR,
} from '../../../libs/blocks/merch/merch.js';

import { mockFetch, unmockFetch, readMockText } from './mocks/fetch.js';
Expand Down Expand Up @@ -187,6 +189,14 @@ describe('Merch Block', () => {
await validatePriceSpan('.merch.price.discount', { template: PRICE_TEMPLATE_DISCOUNT });
});

it('renders merch link to annual price', async () => {
await validatePriceSpan('.merch.price.annual', { template: PRICE_TEMPLATE_ANNUAL });
});

it('renders merch link to the regular price if template is invalid', async () => {
await validatePriceSpan('.merch.price.invalid', { template: PRICE_TEMPLATE_REGULAR });
});

it('renders merch link to tax exclusive price with tax exclusive attribute', async () => {
await validatePriceSpan('.merch.price.tax-exclusive', { forceTaxExclusive: 'true' });
});
Expand Down
10 changes: 10 additions & 0 deletions test/blocks/merch/mocks/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ <h3>Optical price</h3>
href="/tools/ost?osi=08&type=optical&seat=true&tax=true">Price - 632B3ADD940A7FBB7864AA5AD19B8D28 - All Apps </a>
</p>

<h3>Annual price</h3>
<p>Display term, seat and tax texts: <a class="merch price annual"
href="/tools/ost?osi=08&type=annual&seat=true&tax=true">Price - 632B3ADD940A7FBB7864AA5AD19B8D28 - All Apps </a>
</p>

<h3>Invalid price (renderred as regular)</h3>
<p>Display term, seat and tax texts: <a class="merch price invalid"
href="/tools/ost?osi=08&type=invalidType&seat=true&tax=true">Price - 632B3ADD940A7FBB7864AA5AD19B8D28 - All Apps </a>
</p>

<h3>Discount price</h3>
<p>Display term, seat and tax texts: <a class="merch price discount"
href="/tools/ost?osi=08&type=discount">Price - 632B3ADD940A7FBB7864AA5AD19B8D28 - All Apps </a>
Expand Down

0 comments on commit 5dfb72a

Please sign in to comment.