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-140470: allow OST to overwrite landscape #1668

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libs/blocks/ost/ost.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const OST_STYLE_URL = `${OST_BASE}/index.css`;
/** @see https://git.corp.adobe.com/PandoraUI/core/blob/master/packages/react-env-provider/src/component.tsx#L49 */
export const WCS_ENV = 'PROD';
export const WCS_API_KEY = 'wcms-commerce-ims-ro-user-cc';
export const WCS_LANDSCAPE = 'PUBLISHED';

/**
* Maps Franklin page metadata to OST properties.
Expand Down Expand Up @@ -137,6 +138,7 @@ export async function loadOstEnv() {
window.history.replaceState({}, null, newURL);

const environment = searchParameters.get('env') ?? WCS_ENV;
const landscape = searchParameters.get('wcsLandscape') ?? WCS_LANDSCAPE;
const owner = searchParameters.get('owner');
const referrer = searchParameters.get('referrer');
const repo = searchParameters.get('repo');
Expand Down Expand Up @@ -210,6 +212,7 @@ export async function loadOstEnv() {
onSelect,
country,
environment,
landscape,
language,
searchParameters: ostSearchParameters,
searchOfferSelectorId,
Expand Down
5 changes: 3 additions & 2 deletions test/blocks/ost/mocks/ost-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const mockRes = ({ payload, status = 200 } = {}) => new Promise((resolve) => {
});
});

function mockOstDeps({ failStatus = false, failMetadata = false, mockToken } = {}) {
function mockOstDeps({ failStatus = false, failMetadata = false, mockToken, overrideParams } = {}) {
const options = {
country: 'CH',
language: 'de',
workflow: 'UCv2',
};

const params = {
const defaultParams = {
ref: 'main',
repo: 'milo',
owner: 'adobecom',
Expand All @@ -49,6 +49,7 @@ function mockOstDeps({ failStatus = false, failMetadata = false, mockToken } = {
referrer: 'https://adobe.sharepoint.com/:w:/r/sites/adobecom/_layouts/15/Doc.aspx?sourcedoc=%7B341A5A28-4B2F-4BC0-B7D4-6467E22B275C%7D&file=index.docx&action=default&mobileredirect=true',
token: mockToken ? 'aos-access-token' : undefined,
};
const params = { ...defaultParams, ...overrideParams };

window.fetch = sinon.stub()
.onFirstCall()
Expand Down
28 changes: 28 additions & 0 deletions test/blocks/ost/ost.test.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,32 @@ describe('init', () => {
window.adobeid.onReady();
expect(window.adobeIMS.signIn.called).to.be.true;
});

it('opens OST with overwritten WCS "landscape" and "env" values', async () => {
const {
options: { country, language, workflow },
params: { token },
} = mockOstDeps({ mockToken: true, overrideParams: { wcsLandscape: 'DRAFT', env: 'stage' } });

const {
AOS_API_KEY,
CHECKOUT_CLIENT_ID,
WCS_API_KEY,
default: init,
} = await import('../../../libs/blocks/ost/ost.js');
await init(document.body.firstChild);

expect(window.ost.openOfferSelectorTool.called).to.be.true;
expect(window.ost.openOfferSelectorTool.getCall(0).args[0]).to.include({
aosAccessToken: token,
aosApiKey: AOS_API_KEY,
checkoutClientId: CHECKOUT_CLIENT_ID,
country,
environment: 'stage',
landscape: 'DRAFT',
language,
wcsApiKey: WCS_API_KEY,
workflow,
});
});
});
Loading