Skip to content

Commit

Permalink
feat: enhance feature param (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
perco12 authored Jan 30, 2024
1 parent a898583 commit c879cad
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/library/controllers/message/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export default (options = {}) => ({
channel,
ecToken,
contextualComponents,
cspNonce
cspNonce,
features
} = merchantOptions;

// Explicitly select props to pass in to avoid unintentionally sending
Expand All @@ -107,7 +108,8 @@ export default (options = {}) => ({
channel,
ecToken,
contextualComponents,
cspNonce
cspNonce,
features
};
const modalProps = {
...commonProps,
Expand Down
6 changes: 4 additions & 2 deletions src/library/controllers/modal/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const memoizedModal = memoizeOnProps(
ecToken,
contextualComponents,
cspNonce,
integrationIdentifier
integrationIdentifier,
features
}) => {
addPerformanceMeasure(PERFORMANCE_MEASURE_KEYS.FIRST_MODAL_RENDER_DELAY);

Expand All @@ -64,7 +65,8 @@ const memoizedModal = memoizeOnProps(
ecToken,
contextualComponents,
cspNonce,
integrationIdentifier
integrationIdentifier,
features
});
// Fired from inside the default onReady callback
let renderProm;
Expand Down
2 changes: 1 addition & 1 deletion src/library/zoid/message/component.js
Original file line number Diff line number Diff line change
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
10 changes: 10 additions & 0 deletions src/library/zoid/message/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
2 changes: 1 addition & 1 deletion src/library/zoid/modal/component.js
Original file line number Diff line number Diff line change
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
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 c879cad

Please sign in to comment.