Skip to content

Commit

Permalink
feat(customer): correctly handle missing customer address ID (#2515)
Browse files Browse the repository at this point in the history
yes this can really happen
  • Loading branch information
griest024 committed Jul 25, 2023
1 parent 546b8a4 commit 4761b9e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export interface MagentoCustomerAddress {
id: number;
id?: number;
region: {
region_code: string;
region_id: number;
};
country_code: string;
street: string[];
company: string;
telephone: string;
postcode: string;
city: string;
firstname: string;
lastname: string;
email: string;
default_billing: boolean;
default_shipping: boolean;
country_code?: string;
street?: string[];
company?: string;
telephone?: string;
postcode?: string;
city?: string;
firstname?: string;
lastname?: string;
email?: string;
default_billing?: boolean;
default_shipping?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,17 @@ describe('@daffodil/customer/driver/magento | magentoCustomerAddressTransform',
expect(result.defaultBilling).toEqual(mockAddress.default_billing);
expect(result.defaultShipping).toEqual(mockAddress.default_shipping);
});

describe('when the ID is null', () => {
beforeEach(() => {
mockAddress = addressFactory.create({
id: null,
});
result = magentoCustomerAddressTransform(mockAddress);
});

it('should set ID to null', () => {
expect(result.id).toBeNull();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DaffCustomerAddress } from '@daffodil/customer';
import { MagentoCustomerAddress } from '../../models/public_api';

export const magentoCustomerAddressTransform = (address: MagentoCustomerAddress): DaffCustomerAddress => ({
id: String(address.id),
id: address.id ? String(address.id) : null,
street: address.street[0],
street2: address.street[1],
city: address.city,
Expand Down

0 comments on commit 4761b9e

Please sign in to comment.