Skip to content

Commit

Permalink
feat(payments): PAYMENTS-8378 Allow sending multiple addresses to tru…
Browse files Browse the repository at this point in the history
…sted_shipping_address endpoint
  • Loading branch information
Tharaae committed Dec 29, 2022
1 parent 4dc78e8 commit a3a49fd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/store/v2/mappers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export function mapToInstrumentPayload(data = {}) {
* @return {Object}
*/
export function mapToTrustedShippingAddressPayload(data = {}) {
if (Array.isArray(data.shippingAddress)) {
return omitNil({
shipping_addresses: data.shippingAddress.map((address) => mapToAddress(address)),
});
}

return omitNil({
shipping_address: mapToAddress(data.shippingAddress),
});
Expand Down
29 changes: 29 additions & 0 deletions test/store/v2/mappers/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,35 @@ describe('StoreMapper', () => {
expect(result).toEqual(expected);
});

it('maps the input object into an array of trusted shipping addresses object in case of multiple addresses', () => {
const { shippingAddress } = trustedShippingAddressDataMock;

const result = mapToTrustedShippingAddressPayload({ ...trustedShippingAddressDataMock, shippingAddress: [shippingAddress, shippingAddress] });

const expectedAddress = {
address_line_1: shippingAddress.addressLine1,
address_line_2: shippingAddress.addressLine2,
city: shippingAddress.city,
company: shippingAddress.company,
country_code: shippingAddress.countryCode,
email: shippingAddress.email,
first_name: shippingAddress.firstName,
last_name: shippingAddress.lastName,
phone: shippingAddress.phone,
postal_code: shippingAddress.postCode,
state: {
code: shippingAddress.provinceCode,
name: shippingAddress.province,
},
};

const expected = expect.objectContaining({
shipping_addresses: [expectedAddress, expectedAddress],
});

expect(result).toEqual(expected);
});

it('accepts null and returns an empty shipping address object', () => {
const result = mapToTrustedShippingAddressPayload();
const expected = {
Expand Down

0 comments on commit a3a49fd

Please sign in to comment.