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

chore: cut release #1059

Merged
merged 1 commit into from
Mar 12, 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
27 changes: 20 additions & 7 deletions src/library/controllers/message/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ import {
import { getMessageComponent } from '../../zoid/message';
import { Modal } from '../modal';

function getMerchantOptions(jsOptions, container) {
const globalOptions = getGlobalState().config;
const inlineOptions = getInlineOptions(container);

// Use the spread operator to clone jsOptions and inlineOptions, while directly overriding and deleting properties as needed
const mergedOptions = {
...globalOptions,
...jsOptions,
...inlineOptions,
// Override pageType if not set in jsOptions but set in placement, prioritize inlineOptions' pageType if available
pageType: inlineOptions.pageType || jsOptions.pageType || inlineOptions.placement || jsOptions.placement
};

// Explicitly delete the placement property from the final mergedOptions
delete mergedOptions.placement;

return mergedOptions;
}

export default (options = {}) => ({
render: (selector = '[data-pp-message]') => {
addPerformanceMeasure(PERFORMANCE_MEASURE_KEYS.FIRST_RENDER_DELAY);
Expand Down Expand Up @@ -64,10 +83,7 @@ export default (options = {}) => ({
// return resolved render and updateProps
const renderOrUpdateMessage = () => {
try {
const merchantOptions = objectMerge(
getGlobalState().config,
objectMerge(options, getInlineOptions(container))
);
const merchantOptions = getMerchantOptions(options, container);

if (!container.hasAttribute('data-pp-id')) {
container.setAttribute('data-pp-id', nextIndex());
Expand All @@ -80,7 +96,6 @@ export default (options = {}) => ({
customerId,
currency,
amount,
placement,
pageType,
style,
offer,
Expand Down Expand Up @@ -119,7 +134,6 @@ export default (options = {}) => ({
const messageProps = {
...commonProps,
index,
placement,
pageType,
style,
offer,
Expand Down Expand Up @@ -166,7 +180,6 @@ export default (options = {}) => ({
style: ${JSON.stringify(style)},
amount: ${amount},
buyerCountry: ${buyerCountry},
placement: ${placement},
pageType: ${pageType},

renderStart: ${new Date(renderStart).toLocaleString()},
Expand Down
4 changes: 3 additions & 1 deletion src/library/controllers/message/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
isZoidComponent,
ppDebug,
getOverflowObserver,
ensureTreatments
ensureTreatments,
getPageType
} from '../../../utils';
import Messages from './adapter';
import { getMessageComponent } from '../../zoid/message';
Expand All @@ -34,6 +35,7 @@ export default function setup() {
account: partnerAccount || getAccount(),
merchantId: partnerAccount && getAccount(),
currency: getCurrency(),
pageType: getPageType(),
...inlineScriptOptions
});
}
Expand Down
6 changes: 0 additions & 6 deletions src/library/zoid/message/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ export default createGlobalVariableGetter('__paypal_credit_message__', () =>
required: false,
value: validate.currency
},
placement: {
type: 'string',
queryParam: true,
required: false,
value: validate.placement
},
pageType: {
type: 'string',
queryParam: 'page_type',
Expand Down
24 changes: 4 additions & 20 deletions src/library/zoid/message/validation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import arrayIncludes from 'core-js-pure/stable/array/includes';
import numberIsNaN from 'core-js-pure/stable/number/is-nan';
import stringStartsWith from 'core-js-pure/stable/string/starts-with';
import { logger, memoize, getEnv, getPageType } from '../../../utils';
import { logger, memoize, getEnv } from '../../../utils';
import { OFFER } from '../../../utils/constants';

export const Types = {
Expand Down Expand Up @@ -188,30 +188,14 @@ export default {

return undefined;
},
placement: ({ props: { placement } }) => {
if (typeof placement !== 'undefined') {
const options = ['home', 'category', 'product', 'cart', 'payment', 'product-list'];

if (!validateType(Types.STRING, placement)) {
logInvalidType('placement', Types.STRING, placement);
} else if (!arrayIncludes(options, placement)) {
logInvalidOption('placement', options, placement);
} else {
return placement;
}
}

return undefined;
},
pageType: ({ props: { pageType } }) => {
const sdkPageType = getPageType();
if (sdkPageType) {
return sdkPageType;
}
if (typeof pageType !== 'undefined') {
const options = [
'home',
'category',
'product',
'payment',
'product-list',
'product-listing',
'search-results',
'product-details',
Expand Down
34 changes: 4 additions & 30 deletions tests/unit/spec/src/zoid/message/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,38 +242,13 @@ describe('validate', () => {
);
});
});

test('validates placement', () => {
['home', 'category', 'product', 'cart', 'payment', 'product-list'].forEach(supportedPlacement => {
const placement = validate.placement({ props: { placement: supportedPlacement } });

expect(placement).toEqual(supportedPlacement);
expect(console.warn).not.toHaveBeenCalled();
});

{
const placement = validate.placement({ props: {} });

expect(placement).toBeUndefined();
expect(console.warn).not.toHaveBeenCalled();
}

[12345, 'abc', null].forEach((invalidPlacement, index) => {
const placement = validate.placement({ props: { placement: invalidPlacement } });

expect(placement).toBeUndefined();
expect(console.warn).toHaveBeenCalledTimes(index + 1);
expect(console.warn).toHaveBeenLastCalledWith(
expect.stringContaining('invalid_option_value'),
expect.objectContaining({ location: 'placement' })
);
});
});

test('validates pageType', () => {
test('validates pageType with placement values added', () => {
[
'home',
'category',
'product',
'payment',
'product-list',
'product-listing',
'search-results',
'product-details',
Expand Down Expand Up @@ -305,7 +280,6 @@ describe('validate', () => {
);
});
});

test('validates buyerCountry', () => {
['US', 'DE', 'FR', 'GB', 'AU'].forEach(supportedBuyerCountry => {
const buyerCountry = validate.buyerCountry({ props: { buyerCountry: supportedBuyerCountry } });
Expand Down
Loading