Skip to content
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
12 changes: 12 additions & 0 deletions __tests__/core/collectElement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,18 @@ describe('test Collect Element class', () => {
expect(collectElement.getUnformattedValue()).toBe('4111111111111111');
});

it('should remove hyphens from value', () => {
const elementInput = {
table: 'cards',
column: 'number',
type: ElementType.CARD_NUMBER,
containerType: ContainerType.COLLECT,
};
const collectElement = new CollectElement(elementInput, {}, context);
collectElement.updateValue('4111-1111-1111-1111');
expect(collectElement.getUnformattedValue()).toBe('4111111111111111');
});

it('test format option in card number element', () => {
const formatTestCases = [
// Test different valid formats for the card number
Expand Down
10 changes: 10 additions & 0 deletions __tests__/utils/helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ describe('test getReturnValue function', () => {
).toBe('4111111111111111');
});

it('should return unformatted value for card number element', () => {
expect(
getReturnValue('4111 1111 1111 1111', true, ElementType.CARD_NUMBER)
).toBe('4111111111111111');

expect(
getReturnValue('4111-1111-1111-1111', true, ElementType.CARD_NUMBER)
).toBe('4111111111111111');
});

it('should return non string value when return value is true', () => {
expect(getReturnValue(1000, true, ElementType.INPUT_FIELD)).toBe(1000);
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export const getReturnValue = (
) => {
if (typeof value === 'string') {
if (elementType === ElementType.CARD_NUMBER) {
value = value && value.replace(/\s/g, '');
value = value && value.replace(/[\s-]/g, '');
if (!doesReturnValue) {
const threshold =
cardType !== CardType.DEFAULT && cardType === CardType.AMEX ? 6 : 8;
Expand Down