Skip to content

Commit

Permalink
chore: cut release (#1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeul authored Jan 30, 2024
2 parents 7bff85c + c879cad commit 14740d4
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/components/message/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const Message = function ({ markup, meta, parentStyles, warnings }) {
style,
merchantConfigHash,
channel,
contextualComponent,
contextualComponents,
treatmentsHash,
disableSetCookie,
features
Expand All @@ -143,7 +143,7 @@ const Message = function ({ markup, meta, parentStyles, warnings }) {
merchantId,
merchantConfigHash,
channel,
contextualComponent,
contextualComponents,
disableSetCookie,
features
});
Expand All @@ -167,7 +167,7 @@ const Message = function ({ markup, meta, parentStyles, warnings }) {
stageTag,
merchant_config: merchantConfigHash,
channel,
contextualComponent,
contextualComponents,
deviceID: getOrCreateDeviceID(),
treatments: treatmentsHash,
disableSetCookie,
Expand Down
4 changes: 2 additions & 2 deletions src/components/modal/v2/lib/hooks/calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function useCalculator({ autoSubmit = false } = {}) {
integrationType,
channel,
ecToken,
contextualComponent,
contextualComponents,
devTouchpoint,
disableSetCookie,
features
Expand Down Expand Up @@ -94,7 +94,7 @@ export default function useCalculator({ autoSubmit = false } = {}) {
integrationType,
channel,
ecToken,
contextualComponent,
contextualComponents,
devTouchpoint,
deviceID: getOrCreateDeviceID(),
disableSetCookie,
Expand Down
4 changes: 2 additions & 2 deletions src/components/modal/v2/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const getContent = memoize(
integrationType,
channel,
ecToken,
contextualComponent,
contextualComponents,
devTouchpoint,
disableSetCookie,
features
Expand All @@ -43,7 +43,7 @@ export const getContent = memoize(
integrationType,
channel,
ec_token: ecToken,
contextual_component: contextualComponent,
contextual_components: contextualComponents,
devTouchpoint,
disableSetCookie,
features
Expand Down
4 changes: 2 additions & 2 deletions src/components/modal/v2/parts/Container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Container = ({ children }) => {
stageTag,
channel,
ecToken,
contextualComponent,
contextualComponents,
disableSetCookie,
features
} = useXProps();
Expand Down Expand Up @@ -78,7 +78,7 @@ const Container = ({ children }) => {
stageTag,
channel,
ecToken,
contextualComponent,
contextualComponents,
deviceID: getOrCreateDeviceID(),
disableSetCookie,
features
Expand Down
12 changes: 7 additions & 5 deletions src/library/controllers/message/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ export default (options = {}) => ({
onApply,
channel,
ecToken,
contextualComponent,
cspNonce
contextualComponents,
cspNonce,
features
} = merchantOptions;

// Explicitly select props to pass in to avoid unintentionally sending
Expand All @@ -106,8 +107,9 @@ export default (options = {}) => ({
ignoreCache,
channel,
ecToken,
contextualComponent,
cspNonce
contextualComponents,
cspNonce,
features
};
const modalProps = {
...commonProps,
Expand Down Expand Up @@ -156,7 +158,7 @@ export default (options = {}) => ({
ignoreCache: ${ignoreCache},
channel: ${channel},
ecToken: ${ecToken},
contextualComponent: ${contextualComponent},
contextualComponents: ${contextualComponents},
index: data-pp-id="${index}",
style: ${JSON.stringify(style)},
Expand Down
10 changes: 6 additions & 4 deletions src/library/controllers/modal/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ const memoizedModal = memoizeOnProps(
onClose,
channel,
ecToken,
contextualComponent,
contextualComponents,
cspNonce,
integrationIdentifier
integrationIdentifier,
features
}) => {
addPerformanceMeasure(PERFORMANCE_MEASURE_KEYS.FIRST_MODAL_RENDER_DELAY);

Expand All @@ -62,9 +63,10 @@ const memoizedModal = memoizeOnProps(
onClose,
channel,
ecToken,
contextualComponent,
contextualComponents,
cspNonce,
integrationIdentifier
integrationIdentifier,
features
});
// Fired from inside the default onReady callback
let renderProm;
Expand Down
8 changes: 4 additions & 4 deletions src/library/zoid/message/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ export default createGlobalVariableGetter('__paypal_credit_message__', () =>
required: false,
value: validate.ecToken
},
contextualComponent: {
contextualComponents: {
type: 'string',
queryParam: 'contextual_component',
queryParam: 'contextual_components',
required: false,
value: validate.contextualComponent
value: validate.contextualComponents
},
// Callbacks
onClick: {
Expand Down Expand Up @@ -473,7 +473,7 @@ export default createGlobalVariableGetter('__paypal_credit_message__', () =>
type: 'string',
queryParam: 'features',
required: false,
value: getFeatures
value: validate.features ?? getFeatures
}
}
})
Expand Down
32 changes: 21 additions & 11 deletions src/library/zoid/message/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,30 +237,30 @@ export default {

return undefined;
},
contextualComponent: ({ props: { contextualComponent } }) => {
if (typeof contextualComponent !== 'undefined') {
if (!validateType(Types.STRING, contextualComponent)) {
logInvalidType('contextualComponent', Types.STRING, contextualComponent);
contextualComponents: ({ props: { contextualComponents } }) => {
if (typeof contextualComponents !== 'undefined') {
if (!validateType(Types.STRING, contextualComponents)) {
logInvalidType('contextualComponents', Types.STRING, contextualComponents);
return undefined;
}

// contextualComponent values can either be a single string value or a comma-separated string of values
const typesArray = contextualComponent.toUpperCase().split(',');
const typesArray = contextualComponents.toUpperCase().split(',');

// Check if values are of the same type (all buttons or all marks)
const allButtons = typesArray.every(type => type.endsWith('_BUTTON'));
const allMarks = typesArray.every(type => type.endsWith('_MARK'));

if (!allButtons && !allMarks) {
logInvalidCombination(
'contextualComponent',
"Expected all contextualComponent values to be either of type '_button' or '_mark'",
contextualComponent
'contextualComponents',
"Expected all contextualComponents values to be either of type 'button' or 'mark'",
contextualComponents
);
} else if (typesArray.filter(type => type.endsWith('_mark')).length > 1) {
logInvalid('contextualComponent', 'Ensure only one type of _mark value is provided.');
} else if (typesArray.filter(type => type.endsWith('_MARK')).length > 1) {
logInvalid('contextualComponents', 'Ensure only one type of mark value is provided.');
} else {
return contextualComponent.toUpperCase().split(',').sort().join(',');
return contextualComponents.toUpperCase().split(',').sort().join(',');
}
}

Expand All @@ -285,6 +285,16 @@ export default {
return merchantConfig;
}

return undefined;
},
features: ({ props: { features } }) => {
if (typeof features !== 'undefined') {
if (!validateType(Types.STRING, features)) {
logInvalidType('features', Types.STRING, features);
} else {
return features;
}
}
return undefined;
}
};
8 changes: 4 additions & 4 deletions src/library/zoid/modal/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ export default createGlobalVariableGetter('__paypal_credit_modal__', () =>
required: false,
value: validate.ecToken
},
contextualComponent: {
contextualComponents: {
type: 'string',
queryParam: 'contextual_component',
queryParam: 'contextual_components',
required: false,
value: validate.contextualComponent
value: validate.contextualComponents
},

// Callbacks
Expand Down Expand Up @@ -442,7 +442,7 @@ export default createGlobalVariableGetter('__paypal_credit_modal__', () =>
type: 'string',
queryParam: 'features',
required: false,
value: getFeatures
value: validate.features ?? getFeatures
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/utils/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function getInlineOptions(container) {
merchantid: 'merchantId',
cspnonce: 'cspNonce',
ectoken: 'ecToken',
contextualcomponent: 'contextualComponent',
contextualcomponents: 'contextualComponents',
customerid: 'customerId',
fontfamily: 'fontFamily',
fontsource: 'fontSource',
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/spec/src/zoid/message/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,27 @@ describe('validate', () => {
);
});
});
test('validates features', () => {
// features passed
['DEMO', 'test', 'FEATURE'].forEach(validFeatures => {
const features = validate.features({ props: { features: validFeatures } });

expect(features).toEqual(validFeatures);
expect(console.warn).not.toHaveBeenCalled();
});
// no features passed
{
const features = validate.features({ props: {} });

expect(features).toBeUndefined();
expect(console.warn).not.toHaveBeenCalled();
}
// invalid features pass
[12345, null, {}, ['Hi']].forEach((invalidFeature, index) => {
const features = validate.features({ props: { features: invalidFeature } });

expect(features).toBeUndefined();
expect(console.warn).toHaveBeenCalledTimes(index + 1);
});
});
});

0 comments on commit 14740d4

Please sign in to comment.