Skip to content

Commit

Permalink
fix review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
3ch023 committed Aug 14, 2024
1 parent a0f98fa commit 535afeb
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 31 deletions.
6 changes: 0 additions & 6 deletions libs/deps/commerce.js

This file was deleted.

4 changes: 2 additions & 2 deletions libs/deps/mas/commerce.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions libs/deps/mas/mas.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions libs/features/mas/commerce/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const PARAM_LANDSCAPE = 'commerce.landscape';
export const PARAM_AOS_API_KEY = 'commerce.aosKey';
export const PARAM_WCS_API_KEY = 'commerce.wcsKey';

export const WCS_PROD_URL = 'https://www.adobe.com/web_commerce_artifact';
export const WCS_STAGE_URL = 'https://www.stage.adobe.com/web_commerce_artifact_stage';

export const STATE_FAILED = 'failed';
export const STATE_PENDING = 'pending';
export const STATE_RESOLVED = 'resolved';
Expand Down
18 changes: 8 additions & 10 deletions libs/features/mas/commerce/src/settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PARAM_ENV, PARAM_LANDSCAPE, Landscape } from './constants.js';
import { PARAM_ENV, PARAM_LANDSCAPE, Landscape, WCS_PROD_URL, WCS_STAGE_URL } from './constants.js';

Check warning on line 1 in libs/features/mas/commerce/src/settings.js

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 File ignored because of a matching ignore pattern. Use "--no-ignore" to override. Raw Output: {"fatal":false,"severity":1,"message":"File ignored because of a matching ignore pattern. Use \"--no-ignore\" to override."}
import { Defaults } from './defaults.js';
import {
CheckoutWorkflow,
Expand Down Expand Up @@ -133,16 +133,14 @@ function getSettings(config = {}) {
// TODO: add alias names for meta, search and storage
// See https://git.corp.adobe.com/wcms/tacocat.js/pull/348#discussion_r6557570
const { commerce = {}, locale = undefined } = config;
const lowHostEnv = ['local', 'stage'].includes(config.env?.name);
let env = Env.PRODUCTION;
let wcsURL = 'https://www.adobe.com/web_commerce_artifact';
if (lowHostEnv) {
wcsURL = 'https://www.stage.adobe.com/web_commerce_artifact';
const forceWcsStage = getParameter(PARAM_ENV, commerce, { metadata: false }) === 'stage';
if (forceWcsStage) {
env = Env.STAGE;
wcsURL = `${wcsURL}_stage`;
}
let wcsURL = WCS_PROD_URL;

const lowHostEnv = ['local', 'stage'].includes(config.env?.name);
const forceWcsStage = getParameter(PARAM_ENV, commerce, { metadata: false }) === 'stage';
if (lowHostEnv && forceWcsStage) {
env = Env.STAGE;
wcsURL = WCS_STAGE_URL;
}

const checkoutClientId =
Expand Down
28 changes: 17 additions & 11 deletions libs/features/mas/commerce/test/settings.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Env } from '../src/external.js';
import { Landscape } from '../src/constants.js';
import { Landscape, WCS_PROD_URL, WCS_STAGE_URL } from '../src/constants.js';
import { Defaults } from '../src/defaults.js';
import { getSettings } from '../src/settings.js';

Expand Down Expand Up @@ -77,7 +77,7 @@ describe('getSettings', () => {
locale: "en_US",
priceLiteralsURL: undefined,
priceLiteralsPromise: undefined,
wcsURL: 'https://www.stage.adobe.com/web_commerce_artifact'
wcsURL: WCS_STAGE_URL
});
});

Expand Down Expand Up @@ -113,55 +113,61 @@ describe('getSettings', () => {
priceLiteralsPromise: undefined,
quantity: [Defaults.quantity],
wcsApiKey,
wcsURL: 'https://www.stage.adobe.com/web_commerce_artifact_stage',
wcsURL: WCS_STAGE_URL,
landscape: Landscape.DRAFT,
});
window.sessionStorage.removeItem(PARAM_ENV);
});

it('host env "local" -> WCS prod origin + stage akamai', () => {
it('host env "local" -> WCS prod origin + prod akamai', () => {
const config = { commerce: {}, env: { name: 'local' }, };
const settings = getSettings(config);
expect(settings.wcsURL).to.equal('https://www.stage.adobe.com/web_commerce_artifact');
expect(settings.wcsURL).to.equal(WCS_PROD_URL);
expect(settings.env).to.equal(Env.PRODUCTION);
});

it('host env "stage" -> WCS prod origin + stage akamai', () => {
it('host env "stage" -> WCS prod origin + prod akamai', () => {
const config = { commerce: {}, env: { name: 'stage' }, };
const settings = getSettings(config);
expect(settings.wcsURL).to.equal('https://www.stage.adobe.com/web_commerce_artifact');
expect(settings.wcsURL).to.equal(WCS_PROD_URL);
expect(settings.env).to.equal(Env.PRODUCTION);
});

it('host env "prod" -> WCS prod origin + prod akamai', () => {
const config = { commerce: {}, env: { name: 'prod' }, };
const settings = getSettings(config);
expect(settings.wcsURL).to.equal('https://www.adobe.com/web_commerce_artifact');
expect(settings.wcsURL).to.equal(WCS_PROD_URL);
expect(settings.env).to.equal(Env.PRODUCTION);
});

it('host env "local" - override landscape and WCS origin (_stage)', () => {
window.sessionStorage.setItem(PARAM_ENV, 'stage');
window.sessionStorage.setItem(PARAM_LANDSCAPE, 'DRAFT');
const config = { commerce: {}, env: { name: 'local' }, };
const settings = getSettings(config);
expect(settings.wcsURL).to.equal('https://www.stage.adobe.com/web_commerce_artifact_stage');
expect(settings.wcsURL).to.equal(WCS_STAGE_URL);
expect(settings.landscape).to.equal(Landscape.DRAFT);
expect(settings.env).to.equal(Env.STAGE);
});

it('host env "stage" - override landscape and WCS origin (_stage)', () => {
window.sessionStorage.setItem(PARAM_ENV, 'stage');
window.sessionStorage.setItem(PARAM_LANDSCAPE, 'DRAFT');
const config = { commerce: {}, env: { name: 'stage' }, };
const settings = getSettings(config);
expect(settings.wcsURL).to.equal('https://www.stage.adobe.com/web_commerce_artifact_stage');
expect(settings.wcsURL).to.equal(WCS_STAGE_URL);
expect(settings.landscape).to.equal(Landscape.DRAFT);
expect(settings.env).to.equal(Env.STAGE);
});

it('if host env is "prod" - cant override landscape or WCS origin', () => {
window.sessionStorage.setItem(PARAM_ENV, 'stage');
window.sessionStorage.setItem(PARAM_LANDSCAPE, 'DRAFT');
const config = { commerce: {}, env: { name: 'prod' }, };
const settings = getSettings(config);
expect(settings.wcsURL).to.equal('https://www.adobe.com/web_commerce_artifact');
expect(settings.wcsURL).to.equal(WCS_PROD_URL);
expect(settings.landscape).to.equal(Landscape.PUBLISHED);
expect(settings.env).to.equal(Env.PRODUCTION);
});

[
Expand Down

0 comments on commit 535afeb

Please sign in to comment.