From 6fcdf15aa3ba7ab29a8b0ee60ef9726dbea877e2 Mon Sep 17 00:00:00 2001 From: Mariia Lukianets Date: Mon, 12 Aug 2024 11:03:44 +0200 Subject: [PATCH] fix request&settings test --- libs/features/mas/commerce/src/wcs.js | 15 +- libs/features/mas/commerce/stats.json | 1 - .../mas/commerce/test/settings.test.js | 133 ++++++++++++------ 3 files changed, 105 insertions(+), 44 deletions(-) delete mode 100644 libs/features/mas/commerce/stats.json diff --git a/libs/features/mas/commerce/src/wcs.js b/libs/features/mas/commerce/src/wcs.js index 0b82cec877..06ed43af53 100644 --- a/libs/features/mas/commerce/src/wcs.js +++ b/libs/features/mas/commerce/src/wcs.js @@ -52,8 +52,19 @@ export function Wcs({ settings }) { try { log.debug('Fetching:', options); options.offerSelectorIds = options.offerSelectorIds.sort(); - const url = `${settings.wcsURL}?offer_selector_ids=${options.offerSelectorIds}&country=${options.country}&language=${options.language}&locale=${options.locale}&api_key=${apiKey}&landscape=${env === Env.STAGE ? 'ALL' : settings.landscape}`; - const response = await fetch(url); + const url = new URL(settings.wcsURL); + url.searchParams.set('offer_selector_ids', options.offerSelectorIds.join(',')); + url.searchParams.set('country', options.country); + url.searchParams.set('language', options.language); + if (options.currency) { + url.searchParams.set('currency', options.currency); + } + url.searchParams.set('locale', options.locale); + url.searchParams.set('promotion_code', options.promotionCode); + url.searchParams.set('landscape', env === Env.STAGE ? 'ALL' : settings.landscape); + url.searchParams.set('api_key', apiKey); + + const response = await fetch(url.toString()); if (response.ok) { const data = await response.json(); log.debug('Fetched:', options, data); diff --git a/libs/features/mas/commerce/stats.json b/libs/features/mas/commerce/stats.json deleted file mode 100644 index ffea41419b..0000000000 --- a/libs/features/mas/commerce/stats.json +++ /dev/null @@ -1 +0,0 @@ -{"inputs":{"../node_modules/@pandora/data-source-utils/esm/exceptions.js":{"bytes":1841,"imports":[],"format":"esm"},"../node_modules/@pandora/data-source-utils/esm/baseClient.js":{"bytes":3349,"imports":[{"path":"../node_modules/@pandora/data-source-utils/esm/exceptions.js","kind":"import-statement","original":"./exceptions"}],"format":"esm"},"../node_modules/@pandora/data-source-utils/esm/types.js":{"bytes":621,"imports":[],"format":"esm"},"../node_modules/@pandora/data-source-utils/esm/index.js":{"bytes":929,"imports":[{"path":"../node_modules/@pandora/data-source-utils/esm/baseClient.js","kind":"import-statement","original":"./baseClient"},{"path":"../node_modules/@pandora/data-source-utils/esm/types.js","kind":"import-statement","original":"./types"},{"path":"../node_modules/@pandora/data-source-utils/esm/exceptions.js","kind":"import-statement","original":"./exceptions"}],"format":"esm"},"../node_modules/@pandora/commerce-checkout-url-builder/esm/CheckoutType.js":{"bytes":1196,"imports":[],"format":"esm"},"../node_modules/@pandora/commerce-checkout-url-builder/esm/WorkflowStep.js":{"bytes":1552,"imports":[],"format":"esm"},"../node_modules/@pandora/commerce-checkout-url-builder/esm/mapParameterName.js":{"bytes":1419,"imports":[],"format":"esm"},"../node_modules/@pandora/commerce-checkout-url-builder/esm/build.js":{"bytes":4041,"imports":[{"path":"../node_modules/@pandora/data-source-utils/esm/index.js","kind":"import-statement","original":"@pandora/data-source-utils"},{"path":"../node_modules/@pandora/commerce-checkout-url-builder/esm/mapParameterName.js","kind":"import-statement","original":"./mapParameterName"}],"format":"esm"},"../node_modules/@pandora/commerce-checkout-url-builder/esm/ucv2/build-UCv2-url.js":{"bytes":3314,"imports":[{"path":"../node_modules/@pandora/commerce-checkout-url-builder/esm/build.js","kind":"import-statement","original":"../build"}],"format":"esm"},"../node_modules/@pandora/commerce-checkout-url-builder/esm/ucv3/build-UCv3-url.js":{"bytes":5293,"imports":[{"path":"../node_modules/@pandora/data-source-utils/esm/index.js","kind":"import-statement","original":"@pandora/data-source-utils"},{"path":"../node_modules/@pandora/commerce-checkout-url-builder/esm/WorkflowStep.js","kind":"import-statement","original":"../WorkflowStep"},{"path":"../node_modules/@pandora/commerce-checkout-url-builder/esm/build.js","kind":"import-statement","original":"../build"}],"format":"esm"},"../node_modules/@pandora/commerce-checkout-url-builder/esm/index.js":{"bytes":1487,"imports":[{"path":"../node_modules/@pandora/data-source-utils/esm/index.js","kind":"import-statement","original":"@pandora/data-source-utils"},{"path":"../node_modules/@pandora/commerce-checkout-url-builder/esm/CheckoutType.js","kind":"import-statement","original":"./CheckoutType"},{"path":"../node_modules/@pandora/commerce-checkout-url-builder/esm/WorkflowStep.js","kind":"import-statement","original":"./WorkflowStep"},{"path":"../node_modules/@pandora/commerce-checkout-url-builder/esm/ucv2/build-UCv2-url.js","kind":"import-statement","original":"./ucv2/build-UCv2-url"},{"path":"../node_modules/@pandora/commerce-checkout-url-builder/esm/ucv3/build-UCv3-url.js","kind":"import-statement","original":"./ucv3/build-UCv3-url"}],"format":"esm"},"../node_modules/@pandora/data-models-odm/esm/businessDimensions.js":{"bytes":2114,"imports":[],"format":"esm"},"../node_modules/@pandora/data-models-odm/esm/index.js":{"bytes":130,"imports":[{"path":"../node_modules/@pandora/data-models-odm/esm/businessDimensions.js","kind":"import-statement","original":"./businessDimensions"}],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/utilities.js":{"bytes":5700,"imports":[],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/log.js":{"bytes":2057,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/utilities.js","kind":"import-statement","original":"./utilities"}],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/scaffolds.js":{"bytes":1441,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/log.js","kind":"import-statement","original":"./log"},{"path":"../node_modules/@dexter/tacocat-core/src/utilities.js","kind":"import-statement","original":"./utilities"}],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/deferral.js":{"bytes":1184,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/scaffolds.js","kind":"import-statement","original":"./scaffolds"},{"path":"../node_modules/@dexter/tacocat-core/src/utilities.js","kind":"import-statement","original":"./utilities"}],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/lana.js":{"bytes":6194,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/log.js","kind":"import-statement","original":"./log"}],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/placeholderContext.js":{"bytes":1846,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/scaffolds.js","kind":"import-statement","original":"./scaffolds"},{"path":"../node_modules/@dexter/tacocat-core/src/utilities.js","kind":"import-statement","original":"./utilities"}],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/placeholderProvider.js":{"bytes":3010,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/placeholderContext.js","kind":"import-statement","original":"./placeholderContext"},{"path":"../node_modules/@dexter/tacocat-core/src/scaffolds.js","kind":"import-statement","original":"./scaffolds"},{"path":"../node_modules/@dexter/tacocat-core/src/utilities.js","kind":"import-statement","original":"./utilities"}],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/placeholderStages.js":{"bytes":433,"imports":[],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/placeholderState.js":{"bytes":2957,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/placeholderContext.js","kind":"import-statement","original":"./placeholderContext"},{"path":"../node_modules/@dexter/tacocat-core/src/placeholderStages.js","kind":"import-statement","original":"./placeholderStages"},{"path":"../node_modules/@dexter/tacocat-core/src/scaffolds.js","kind":"import-statement","original":"./scaffolds"},{"path":"../node_modules/@dexter/tacocat-core/src/utilities.js","kind":"import-statement","original":"./utilities"}],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/placeholderTemplate.js":{"bytes":1796,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/scaffolds.js","kind":"import-statement","original":"./scaffolds"},{"path":"../node_modules/@dexter/tacocat-core/src/placeholderStages.js","kind":"import-statement","original":"./placeholderStages"},{"path":"../node_modules/@dexter/tacocat-core/src/utilities.js","kind":"import-statement","original":"./utilities"}],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/placeholderEngine.js":{"bytes":8668,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/deferral.js","kind":"import-statement","original":"./deferral"},{"path":"../node_modules/@dexter/tacocat-core/src/placeholderContext.js","kind":"import-statement","original":"./placeholderContext"},{"path":"../node_modules/@dexter/tacocat-core/src/placeholderProvider.js","kind":"import-statement","original":"./placeholderProvider"},{"path":"../node_modules/@dexter/tacocat-core/src/placeholderState.js","kind":"import-statement","original":"./placeholderState"},{"path":"../node_modules/@dexter/tacocat-core/src/placeholderStages.js","kind":"import-statement","original":"./placeholderStages"},{"path":"../node_modules/@dexter/tacocat-core/src/placeholderTemplate.js","kind":"import-statement","original":"./placeholderTemplate"},{"path":"../node_modules/@dexter/tacocat-core/src/scaffolds.js","kind":"import-statement","original":"./scaffolds"}],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/retry.js":{"bytes":1837,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/utilities.js","kind":"import-statement","original":"./utilities"}],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/promotion.js":{"bytes":1660,"imports":[],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/wcsUtils.js":{"bytes":3510,"imports":[{"path":"../node_modules/@pandora/data-models-odm/esm/index.js","kind":"import-statement","original":"@pandora/data-models-odm"}],"format":"esm"},"../node_modules/@dexter/tacocat-core/src/index.js":{"bytes":405,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/deferral.js","kind":"import-statement","original":"./deferral"},{"path":"../node_modules/@dexter/tacocat-core/src/log.js","kind":"import-statement","original":"./log"},{"path":"../node_modules/@dexter/tacocat-core/src/lana.js","kind":"import-statement","original":"./lana"},{"path":"../node_modules/@dexter/tacocat-core/src/placeholderContext.js","kind":"import-statement","original":"./placeholderContext"},{"path":"../node_modules/@dexter/tacocat-core/src/placeholderProvider.js","kind":"import-statement","original":"./placeholderProvider"},{"path":"../node_modules/@dexter/tacocat-core/src/placeholderEngine.js","kind":"import-statement","original":"./placeholderEngine"},{"path":"../node_modules/@dexter/tacocat-core/src/placeholderTemplate.js","kind":"import-statement","original":"./placeholderTemplate"},{"path":"../node_modules/@dexter/tacocat-core/src/placeholderStages.js","kind":"import-statement","original":"./placeholderStages"},{"path":"../node_modules/@dexter/tacocat-core/src/retry.js","kind":"import-statement","original":"./retry"},{"path":"../node_modules/@dexter/tacocat-core/src/scaffolds.js","kind":"import-statement","original":"./scaffolds"},{"path":"../node_modules/@dexter/tacocat-core/src/utilities.js","kind":"import-statement","original":"./utilities"},{"path":"../node_modules/@dexter/tacocat-core/src/promotion.js","kind":"import-statement","original":"./promotion"},{"path":"../node_modules/@dexter/tacocat-core/src/wcsUtils.js","kind":"import-statement","original":"./wcsUtils"}],"format":"esm"},"../node_modules/tslib/tslib.es6.mjs":{"bytes":16530,"imports":[],"format":"esm"},"../node_modules/@formatjs/icu-messageformat-parser/lib/error.js":{"bytes":4465,"imports":[],"format":"esm"},"../node_modules/@formatjs/icu-messageformat-parser/lib/types.js":{"bytes":2367,"imports":[],"format":"esm"},"../node_modules/@formatjs/icu-messageformat-parser/lib/regex.generated.js":{"bytes":186,"imports":[],"format":"esm"},"../node_modules/@formatjs/icu-skeleton-parser/lib/date-time.js":{"bytes":4886,"imports":[],"format":"esm"},"../node_modules/@formatjs/icu-skeleton-parser/lib/regex.generated.js":{"bytes":104,"imports":[],"format":"esm"},"../node_modules/@formatjs/icu-skeleton-parser/lib/number.js":{"bytes":10662,"imports":[{"path":"../node_modules/tslib/tslib.es6.mjs","kind":"import-statement","original":"tslib"},{"path":"../node_modules/@formatjs/icu-skeleton-parser/lib/regex.generated.js","kind":"import-statement","original":"./regex.generated"}],"format":"esm"},"../node_modules/@formatjs/icu-skeleton-parser/lib/index.js":{"bytes":55,"imports":[{"path":"../node_modules/@formatjs/icu-skeleton-parser/lib/date-time.js","kind":"import-statement","original":"./date-time"},{"path":"../node_modules/@formatjs/icu-skeleton-parser/lib/number.js","kind":"import-statement","original":"./number"}],"format":"esm"},"../node_modules/@formatjs/icu-messageformat-parser/lib/parser.js":{"bytes":48151,"imports":[{"path":"../node_modules/tslib/tslib.es6.mjs","kind":"import-statement","original":"tslib"},{"path":"../node_modules/@formatjs/icu-messageformat-parser/lib/error.js","kind":"import-statement","original":"./error"},{"path":"../node_modules/@formatjs/icu-messageformat-parser/lib/types.js","kind":"import-statement","original":"./types"},{"path":"../node_modules/@formatjs/icu-messageformat-parser/lib/regex.generated.js","kind":"import-statement","original":"./regex.generated"},{"path":"../node_modules/@formatjs/icu-skeleton-parser/lib/index.js","kind":"import-statement","original":"@formatjs/icu-skeleton-parser"}],"format":"esm"},"../node_modules/@formatjs/icu-messageformat-parser/lib/index.js":{"bytes":1642,"imports":[{"path":"../node_modules/tslib/tslib.es6.mjs","kind":"import-statement","original":"tslib"},{"path":"../node_modules/@formatjs/icu-messageformat-parser/lib/error.js","kind":"import-statement","original":"./error"},{"path":"../node_modules/@formatjs/icu-messageformat-parser/lib/parser.js","kind":"import-statement","original":"./parser"},{"path":"../node_modules/@formatjs/icu-messageformat-parser/lib/types.js","kind":"import-statement","original":"./types"},{"path":"../node_modules/@formatjs/icu-messageformat-parser/lib/types.js","kind":"import-statement","original":"./types"}],"format":"esm"},"../node_modules/@formatjs/fast-memoize/lib/index.js":{"bytes":2452,"imports":[],"format":"esm"},"../node_modules/intl-messageformat/lib/src/error.js":{"bytes":2238,"imports":[{"path":"../node_modules/tslib/tslib.es6.mjs","kind":"import-statement","original":"tslib"}],"format":"esm"},"../node_modules/intl-messageformat/lib/src/formatters.js":{"bytes":7008,"imports":[{"path":"../node_modules/@formatjs/icu-messageformat-parser/lib/index.js","kind":"import-statement","original":"@formatjs/icu-messageformat-parser"},{"path":"../node_modules/intl-messageformat/lib/src/error.js","kind":"import-statement","original":"./error"}],"format":"esm"},"../node_modules/intl-messageformat/lib/src/core.js":{"bytes":7776,"imports":[{"path":"../node_modules/tslib/tslib.es6.mjs","kind":"import-statement","original":"tslib"},{"path":"../node_modules/@formatjs/icu-messageformat-parser/lib/index.js","kind":"import-statement","original":"@formatjs/icu-messageformat-parser"},{"path":"../node_modules/@formatjs/fast-memoize/lib/index.js","kind":"import-statement","original":"@formatjs/fast-memoize"},{"path":"../node_modules/intl-messageformat/lib/src/formatters.js","kind":"import-statement","original":"./formatters"}],"format":"esm"},"../node_modules/intl-messageformat/lib/index.js":{"bytes":324,"imports":[{"path":"../node_modules/intl-messageformat/lib/src/core.js","kind":"import-statement","original":"./src/core"},{"path":"../node_modules/intl-messageformat/lib/src/formatters.js","kind":"import-statement","original":"./src/formatters"},{"path":"../node_modules/intl-messageformat/lib/src/core.js","kind":"import-statement","original":"./src/core"},{"path":"../node_modules/intl-messageformat/lib/src/error.js","kind":"import-statement","original":"./src/error"}],"format":"esm"},"../node_modules/@dexter/tacocat-consonant-templates/src/price/numberFormat.js":{"bytes":5253,"imports":[],"format":"esm"},"../node_modules/@dexter/tacocat-consonant-templates/src/price/utilities.js":{"bytes":9848,"imports":[{"path":"../node_modules/@pandora/data-models-odm/esm/index.js","kind":"import-statement","original":"@pandora/data-models-odm"},{"path":"../node_modules/@dexter/tacocat-consonant-templates/src/price/numberFormat.js","kind":"import-statement","original":"./numberFormat.js"}],"format":"esm"},"../node_modules/@dexter/tacocat-consonant-templates/src/price/template.js":{"bytes":11624,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/index.js","kind":"import-statement","original":"@dexter/tacocat-core"},{"path":"../node_modules/intl-messageformat/lib/index.js","kind":"import-statement","original":"intl-messageformat"},{"path":"../node_modules/@dexter/tacocat-consonant-templates/src/price/utilities.js","kind":"import-statement","original":"./utilities"}],"format":"esm"},"../node_modules/@dexter/tacocat-consonant-templates/src/price/index.js":{"bytes":468,"imports":[{"path":"../node_modules/@dexter/tacocat-consonant-templates/src/price/template.js","kind":"import-statement","original":"./template"}],"format":"esm"},"../node_modules/@dexter/tacocat-consonant-templates/src/discount/template.js":{"bytes":1204,"imports":[{"path":"../node_modules/@dexter/tacocat-core/src/index.js","kind":"import-statement","original":"@dexter/tacocat-core"}],"format":"esm"},"../node_modules/@dexter/tacocat-consonant-templates/src/discount/index.js":{"bytes":119,"imports":[{"path":"../node_modules/@dexter/tacocat-consonant-templates/src/discount/template.js","kind":"import-statement","original":"./template"}],"format":"esm"},"../node_modules/@dexter/tacocat-consonant-templates/src/index.js":{"bytes":53,"imports":[{"path":"../node_modules/@dexter/tacocat-consonant-templates/src/price/index.js","kind":"import-statement","original":"./price"},{"path":"../node_modules/@dexter/tacocat-consonant-templates/src/discount/index.js","kind":"import-statement","original":"./discount"}],"format":"esm"},"src/external.js":{"bytes":1880,"imports":[{"path":"../node_modules/@pandora/commerce-checkout-url-builder/esm/index.js","kind":"import-statement","original":"@pandora/commerce-checkout-url-builder"},{"path":"../node_modules/@pandora/data-models-odm/esm/index.js","kind":"import-statement","original":"@pandora/data-models-odm"},{"path":"../node_modules/@dexter/tacocat-consonant-templates/src/index.js","kind":"import-statement","original":"@dexter/tacocat-consonant-templates"},{"path":"../node_modules/@dexter/tacocat-core/src/index.js","kind":"import-statement","original":"@dexter/tacocat-core"}],"format":"esm"},"src/constants.js":{"bytes":1171,"imports":[],"format":"esm"},"src/lana.js":{"bytes":2625,"imports":[],"format":"esm"},"src/defaults.js":{"bytes":863,"imports":[{"path":"src/external.js","kind":"import-statement","original":"./external.js"},{"path":"src/constants.js","kind":"import-statement","original":"./constants.js"}],"format":"esm"},"src/utilities.js":{"bytes":2764,"imports":[{"path":"src/constants.js","kind":"import-statement","original":"./constants.js"},{"path":"src/external.js","kind":"import-statement","original":"./external.js"}],"format":"esm"},"src/settings.js":{"bytes":6531,"imports":[{"path":"src/constants.js","kind":"import-statement","original":"./constants.js"},{"path":"src/defaults.js","kind":"import-statement","original":"./defaults.js"},{"path":"src/external.js","kind":"import-statement","original":"./external.js"},{"path":"src/utilities.js","kind":"import-statement","original":"./utilities.js"}],"format":"esm"},"src/log.js":{"bytes":3694,"imports":[{"path":"src/constants.js","kind":"import-statement","original":"./constants.js"},{"path":"src/external.js","kind":"import-statement","original":"./external.js"},{"path":"src/lana.js","kind":"import-statement","original":"./lana.js"},{"path":"src/settings.js","kind":"import-statement","original":"./settings.js"}],"format":"esm"},"src/placeholder.js":{"bytes":11630,"imports":[{"path":"src/constants.js","kind":"import-statement","original":"./constants.js"},{"path":"src/external.js","kind":"import-statement","original":"./external.js"},{"path":"src/log.js","kind":"import-statement","original":"./log.js"},{"path":"src/utilities.js","kind":"import-statement","original":"./utilities.js"}],"format":"esm"},"src/checkout-link.js":{"bytes":7680,"imports":[{"path":"src/external.js","kind":"import-statement","original":"./external.js"},{"path":"src/placeholder.js","kind":"import-statement","original":"./placeholder.js"},{"path":"src/utilities.js","kind":"import-statement","original":"./utilities.js"},{"path":"","kind":"import-statement","external":true}],"format":"esm"},"src/inline-price.js":{"bytes":8948,"imports":[{"path":"src/placeholder.js","kind":"import-statement","original":"./placeholder.js"},{"path":"src/utilities.js","kind":"import-statement","original":"./utilities.js"},{"path":"src/settings.js","kind":"import-statement","original":"./settings"},{"path":"","kind":"import-statement","external":true}],"format":"esm"},"src/checkout.js":{"bytes":5795,"imports":[{"path":"src/checkout-link.js","kind":"import-statement","original":"./checkout-link.js"},{"path":"src/external.js","kind":"import-statement","original":"./external.js"},{"path":"src/defaults.js","kind":"import-statement","original":"./defaults.js"},{"path":"src/log.js","kind":"import-statement","original":"./log.js"},{"path":"src/utilities.js","kind":"import-statement","original":"./utilities.js"}],"format":"esm"},"src/ims.js":{"bytes":1675,"imports":[{"path":"src/log.js","kind":"import-statement","original":"./log.js"}],"format":"esm"},"src/literals.js":{"bytes":1252,"imports":[{"path":"src/constants.js","kind":"import-statement","original":"./constants.js"},{"path":"src/defaults.js","kind":"import-statement","original":"./defaults.js"},{"path":"src/external.js","kind":"import-statement","original":"./external.js"}],"format":"esm"},"src/price.js":{"bytes":4099,"imports":[{"path":"src/defaults.js","kind":"import-statement","original":"./defaults.js"},{"path":"src/external.js","kind":"import-statement","original":"./external.js"},{"path":"src/inline-price.js","kind":"import-statement","original":"./inline-price.js"},{"path":"src/utilities.js","kind":"import-statement","original":"./utilities.js"}],"format":"esm"},"src/wcs.js":{"bytes":6949,"imports":[{"path":"src/constants.js","kind":"import-statement","original":"./constants.js"},{"path":"src/external.js","kind":"import-statement","original":"./external.js"},{"path":"src/log.js","kind":"import-statement","original":"./log.js"}],"format":"esm"},"src/service.js":{"bytes":5024,"imports":[{"path":"src/checkout.js","kind":"import-statement","original":"./checkout.js"},{"path":"src/constants.js","kind":"import-statement","original":"./constants.js"},{"path":"src/constants.js","kind":"import-statement","original":"./constants.js"},{"path":"src/defaults.js","kind":"import-statement","original":"./defaults.js"},{"path":"src/external.js","kind":"import-statement","original":"./external.js"},{"path":"src/ims.js","kind":"import-statement","original":"./ims.js"},{"path":"src/literals.js","kind":"import-statement","original":"./literals.js"},{"path":"src/log.js","kind":"import-statement","original":"./log.js"},{"path":"src/price.js","kind":"import-statement","original":"./price.js"},{"path":"src/settings.js","kind":"import-statement","original":"./settings.js"},{"path":"src/wcs.js","kind":"import-statement","original":"./wcs.js"},{"path":"src/utilities.js","kind":"import-statement","original":"./utilities.js"},{"path":"","kind":"import-statement","external":true}],"format":"esm"},"src/index.js":{"bytes":823,"imports":[{"path":"src/checkout-link.js","kind":"import-statement","original":"./checkout-link.js"},{"path":"src/constants.js","kind":"import-statement","original":"./constants.js"},{"path":"src/defaults.js","kind":"import-statement","original":"./defaults.js"},{"path":"src/external.js","kind":"import-statement","original":"./external.js"},{"path":"src/inline-price.js","kind":"import-statement","original":"./inline-price.js"},{"path":"src/log.js","kind":"import-statement","original":"./log.js"},{"path":"src/service.js","kind":"import-statement","original":"./service.js"},{"path":"src/settings.js","kind":"import-statement","original":"./settings.js"}],"format":"esm"}},"outputs":{"../../../deps/mas/commerce.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":367292},"../../../deps/mas/commerce.js":{"imports":[],"exports":["CheckoutLink","CheckoutWorkflow","CheckoutWorkflowStep","Defaults","InlinePrice","Landscape","Log","TAG_NAME_SERVICE","WcsCommitment","WcsPlanType","WcsTerm","applyPlanType","getLocaleSettings","getSettings","init","reset"],"entryPoint":"src/index.js","inputs":{"../node_modules/@pandora/data-source-utils/esm/types.js":{"bytesInOutput":255},"../node_modules/@pandora/data-source-utils/esm/index.js":{"bytesInOutput":0},"../node_modules/@pandora/commerce-checkout-url-builder/esm/CheckoutType.js":{"bytesInOutput":59},"../node_modules/@pandora/commerce-checkout-url-builder/esm/WorkflowStep.js":{"bytesInOutput":352},"../node_modules/@pandora/commerce-checkout-url-builder/esm/mapParameterName.js":{"bytesInOutput":377},"../node_modules/@pandora/commerce-checkout-url-builder/esm/build.js":{"bytesInOutput":1300},"../node_modules/@pandora/commerce-checkout-url-builder/esm/ucv2/build-UCv2-url.js":{"bytesInOutput":1313},"../node_modules/@pandora/commerce-checkout-url-builder/esm/ucv3/build-UCv3-url.js":{"bytesInOutput":2061},"../node_modules/@pandora/commerce-checkout-url-builder/esm/index.js":{"bytesInOutput":180},"../node_modules/@pandora/data-models-odm/esm/businessDimensions.js":{"bytesInOutput":1015},"../node_modules/@pandora/data-models-odm/esm/index.js":{"bytesInOutput":0},"../node_modules/@dexter/tacocat-core/src/utilities.js":{"bytesInOutput":1338},"../node_modules/@dexter/tacocat-core/src/log.js":{"bytesInOutput":577},"../node_modules/@dexter/tacocat-core/src/promotion.js":{"bytesInOutput":383},"../node_modules/@dexter/tacocat-core/src/wcsUtils.js":{"bytesInOutput":1085},"../node_modules/tslib/tslib.es6.mjs":{"bytesInOutput":870},"../node_modules/@formatjs/icu-messageformat-parser/lib/error.js":{"bytesInOutput":1683},"../node_modules/@formatjs/icu-messageformat-parser/lib/types.js":{"bytesInOutput":805},"../node_modules/@formatjs/icu-messageformat-parser/lib/regex.generated.js":{"bytesInOutput":54},"../node_modules/@formatjs/icu-skeleton-parser/lib/date-time.js":{"bytesInOutput":2124},"../node_modules/@formatjs/icu-skeleton-parser/lib/index.js":{"bytesInOutput":0},"../node_modules/@formatjs/icu-skeleton-parser/lib/regex.generated.js":{"bytesInOutput":47},"../node_modules/@formatjs/icu-skeleton-parser/lib/number.js":{"bytesInOutput":4200},"../node_modules/@formatjs/icu-messageformat-parser/lib/parser.js":{"bytesInOutput":16430},"../node_modules/@formatjs/icu-messageformat-parser/lib/index.js":{"bytesInOutput":517},"../node_modules/@formatjs/fast-memoize/lib/index.js":{"bytesInOutput":996},"../node_modules/intl-messageformat/lib/src/error.js":{"bytesInOutput":869},"../node_modules/intl-messageformat/lib/src/formatters.js":{"bytesInOutput":2230},"../node_modules/intl-messageformat/lib/src/core.js":{"bytesInOutput":2930},"../node_modules/intl-messageformat/lib/index.js":{"bytesInOutput":10},"../node_modules/@dexter/tacocat-consonant-templates/src/price/numberFormat.js":{"bytesInOutput":1700},"../node_modules/@dexter/tacocat-consonant-templates/src/price/utilities.js":{"bytesInOutput":2014},"../node_modules/@dexter/tacocat-consonant-templates/src/price/template.js":{"bytesInOutput":4150},"../node_modules/@dexter/tacocat-consonant-templates/src/price/index.js":{"bytesInOutput":106},"../node_modules/@dexter/tacocat-consonant-templates/src/discount/template.js":{"bytesInOutput":226},"../node_modules/@dexter/tacocat-consonant-templates/src/discount/index.js":{"bytesInOutput":12},"src/external.js":{"bytesInOutput":149},"src/constants.js":{"bytesInOutput":1047},"src/lana.js":{"bytesInOutput":1116},"src/defaults.js":{"bytesInOutput":478},"src/utilities.js":{"bytesInOutput":687},"src/settings.js":{"bytesInOutput":2787},"src/log.js":{"bytesInOutput":1211},"src/placeholder.js":{"bytesInOutput":3163},"src/checkout-link.js":{"bytesInOutput":2936},"src/inline-price.js":{"bytesInOutput":2805},"src/checkout.js":{"bytesInOutput":1891},"src/ims.js":{"bytesInOutput":618},"src/literals.js":{"bytesInOutput":348},"src/price.js":{"bytesInOutput":1223},"src/wcs.js":{"bytesInOutput":1781},"src/service.js":{"bytesInOutput":1309},"src/index.js":{"bytesInOutput":0}},"bytes":76724}}} \ No newline at end of file diff --git a/libs/features/mas/commerce/test/settings.test.js b/libs/features/mas/commerce/test/settings.test.js index 24325521ea..3572e60bb4 100644 --- a/libs/features/mas/commerce/test/settings.test.js +++ b/libs/features/mas/commerce/test/settings.test.js @@ -12,7 +12,11 @@ describe('getSettings', () => { after(() => { document.head.querySelectorAll('meta').forEach((meta) => meta.remove()); window.history.replaceState({}, '', href); + }); + + afterEach(() => { window.sessionStorage.clear(); + window.history.replaceState({}, '', href); }); before(() => { @@ -29,10 +33,56 @@ describe('getSettings', () => { }); }); - it('uses location search, document metadata and storage', () => { - const checkoutClientId = 'checkout-client-id'; - const url = `${window.location.href}&checkoutClientId=${checkoutClientId}`; - window.history.replaceState({}, '', url); + it('overrides with search parameters', () => { + const checkoutClientId = 'adobecom'; + const checkoutWorkflowStep = 'segmentation'; + const promotionCode = 'nicopromo'; + + const url = new URL(window.location.href); + url.searchParams.set('checkoutClientId', checkoutClientId); + url.searchParams.set('checkoutWorkflowStep', checkoutWorkflowStep); + url.searchParams.set('promotionCode', promotionCode); + url.searchParams.set('displayOldPrice', 'false'); + url.searchParams.set('displayPerUnit', 'true'); + url.searchParams.set('displayRecurrence', 'false'); + url.searchParams.set('displayTax', 'true'); + url.searchParams.set('entitlement', 'true'); + url.searchParams.set('modal', 'true'); + url.searchParams.set('commerce.landscape', 'DRAFT'); + url.searchParams.set('wcsBufferDelay', '30'); + url.searchParams.set('wcsBufferLimit', '5'); + url.searchParams.set('quantity', '2'); + url.searchParams.set('wcsApiKey', 'testapikey'); + window.history.replaceState({}, '', url.toString()); + + const config = { commerce: {}, env: { name: 'stage' }, }; + expect( + getSettings(config), + ).to.deep.equal({ + ...Defaults, + checkoutClientId, + checkoutWorkflowStep, + promotionCode, + displayOldPrice: false, + displayPerUnit: true, + displayRecurrence: false, + displayTax: true, + entitlement: true, + modal: true, + landscape: 'DRAFT', + wcsBufferDelay: 30, + wcsBufferLimit: 5, + quantity: [2], + wcsApiKey: 'testapikey', + locale: "en_US", + priceLiteralsURL: undefined, + priceLiteralsPromise: undefined, + wcsURL: 'https://www.stage.adobe.com/web_commerce_artifact' + }); + }); + + + it('uses document metadata and storage', () => { const wcsApiKey = 'wcs-api-key'; const meta = document.createElement('meta'); meta.content = wcsApiKey; @@ -55,7 +105,6 @@ describe('getSettings', () => { ...Defaults, forceTaxExclusive: true, promotionCode: 'promo1', - checkoutClientId, country: 'NO', env: Env.STAGE, language: 'nb', @@ -64,53 +113,55 @@ describe('getSettings', () => { priceLiteralsPromise: undefined, quantity: [Defaults.quantity], wcsApiKey, - wcsEnv: 'STAGE', + wcsURL: 'https://www.stage.adobe.com/web_commerce_artifact_stage', landscape: Landscape.DRAFT, }); window.sessionStorage.removeItem(PARAM_ENV); }); - it('if host env is "dev" - override commerce landscape', () => { - window.sessionStorage.setItem(PARAM_LANDSCAPE, 'DRAFT'); + it('host env "local" -> WCS prod origin + stage akamai', () => { + const config = { commerce: {}, env: { name: 'local' }, }; + const settings = getSettings(config); + expect(settings.wcsURL).to.equal('https://www.stage.adobe.com/web_commerce_artifact'); + }); - const config = { - commerce: {}, - env: { name: 'local' }, - }; - expect(getSettings(config)).to.deep.equal({ - ...Defaults, - checkoutClientId: 'checkout-client-id', - wcsApiKey: 'wcs-api-key', - env: Env.PRODUCTION, - locale: 'en_US', - priceLiteralsURL: undefined, - priceLiteralsPromise: undefined, - quantity: [Defaults.quantity], - wcsEnv: 'PRODUCTION', - landscape: Landscape.DRAFT, - }); + it('host env "stage" -> WCS prod origin + stage akamai', () => { + const config = { commerce: {}, env: { name: 'stage' }, }; + const settings = getSettings(config); + expect(settings.wcsURL).to.equal('https://www.stage.adobe.com/web_commerce_artifact'); + }); + + 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'); }); - it('if host env is "prod" - doesnt override commerce env and landscape', () => { + 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.landscape).to.equal(Landscape.DRAFT); + }); - const config = { - commerce: {}, - env: { name: 'prod' }, - }; - expect(getSettings(config)).to.deep.equal({ - ...Defaults, - checkoutClientId: 'checkout-client-id', - wcsApiKey: 'wcs-api-key', - env: Env.PRODUCTION, - locale: 'en_US', - priceLiteralsURL: undefined, - priceLiteralsPromise: undefined, - quantity: [Defaults.quantity], - wcsEnv: 'PRODUCTION', - landscape: Landscape.PUBLISHED, - }); + 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.landscape).to.equal(Landscape.DRAFT); + }); + + 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.landscape).to.equal(Landscape.PUBLISHED); }); [