Skip to content

Commit

Permalink
fix(payments): PAYMENTS-2590 Omitting empty string from billing address
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-biren committed Mar 15, 2018
1 parent 8db3d71 commit 6c3dcb7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/common/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { default as includes } from './includes';
export { default as isNil } from './is-nil';
export { default as isObject } from './is-object';
export { default as omitEmptyAndNil } from './omit-empty-and-nil';
export { default as omitNil } from './omit-nil';
export { default as omitProperty } from './omit-property';
export { default as toNumber } from './to-number';
Expand Down
10 changes: 10 additions & 0 deletions src/common/utils/is-empty-or-nil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import isEmpty from './is-empty';
import isNil from './is-nil';

/**
* @param {*} value
* @returns {boolean}
*/
export default function isEmptyOrNil(value) {
return isEmpty(value) || isNil(value);
}
7 changes: 7 additions & 0 deletions src/common/utils/is-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @param {*} value
* @returns {boolean}
*/
export default function isEmpty(value) {
return value === '';
}
10 changes: 10 additions & 0 deletions src/common/utils/omit-empty-and-nil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import isEmptyOrNil from './is-empty-or-nil';
import omitProperty from './omit-property';

/**
* @param {Object} object
* @returns {Object}
*/
export default function omitEmptyAndNil(object) {
return omitProperty(object, isEmptyOrNil);
}
4 changes: 2 additions & 2 deletions src/payment/v1/payment-mappers/order-mapper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { omitNil, toString } from '../../../common/utils';
import { omitEmptyAndNil, omitNil, toString } from '../../../common/utils';

export default class OrderMapper {
/**
Expand Down Expand Up @@ -92,7 +92,7 @@ export default class OrderMapper {
mapToAddress(data, addressKey) {
const address = data[addressKey] || {};

return omitNil({
return omitEmptyAndNil({
city: address.city,
company: address.company,
country_code: address.countryCode,
Expand Down
23 changes: 23 additions & 0 deletions test/payment/v1/payment-mappers/order-mapper.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash';
import OrderMapper from '../../../../src/payment/v1/payment-mappers/order-mapper';
import paymentRequestDataMock from '../../../mocks/payment-request-data';

Expand All @@ -16,6 +17,28 @@ describe('OrderMapper', () => {
expect(instance instanceof OrderMapper).toBeTruthy();
});

it('removes empty fields from billing address', () => {
const mockData = _.cloneDeep(paymentRequestDataMock);
mockData.billingAddress.company = '';
mockData.billingAddress.phone = '';
mockData.billingAddress.addressLine2 = '';

const output = orderMapper.mapToOrder(mockData);

expect(output.billing_address).toEqual({
city: data.billingAddress.city,
country_code: data.billingAddress.countryCode,
country: data.billingAddress.country,
email: data.customer.email,
first_name: data.billingAddress.firstName,
last_name: data.billingAddress.lastName,
state_code: data.billingAddress.provinceCode,
state: data.billingAddress.province,
street_1: data.billingAddress.addressLine1,
zip: data.billingAddress.postCode,
});
});

it('maps the input data into an order object', () => {
const output = orderMapper.mapToOrder(data);

Expand Down

0 comments on commit 6c3dcb7

Please sign in to comment.