import { CustomerAddressConverter } from './customerAddress.converter'; import { CustomerAddressHiboutikDto } from '../hiboutikDTO/customer.hiboutik.dto'; const hiboutikAddress = (overrides: Partial = {}): CustomerAddressHiboutikDto => ({ address_id: 7, customers_id: 42, first_name: 'Jane', last_name: 'Doe', company: 'ACME', phone: '0600000000', address: ' 1 rue de la Paix ', zip_code: '75002', city: 'Paris', state: '', country: 'FRA', other: 'Bât. B', default: 1, ...overrides, }); describe('CustomerAddressConverter', () => { const converter = new CustomerAddressConverter(); it('maps a Hiboutik address', () => { expect(converter.fromHiboutik(hiboutikAddress())).toEqual({ address: '1 rue de la Paix', city: 'Paris', company: 'ACME', country: 'FRA', firstName: 'Jane', hiboutikId: 7, isDefault: true, lastName: 'Doe', other: 'Bât. B', phone: '0600000000', state: null, zipCode: '75002', customer: { connect: { hiboutikId: 42 } }, }); }); it('erases empty optional fields (null) and defaults empty required ones to ""', () => { const address = converter.fromHiboutik(hiboutikAddress({ company: ' ', phone: '', other: '', first_name: '' })); expect(address.company).toBeNull(); expect(address.phone).toBeNull(); expect(address.other).toBeNull(); expect(address.firstName).toBe(''); }); describe('company details', () => { const details = { tax_number: ' FR123 ', company_number: '12345678900012', legal_status: 'SAS', updated_at: '2026-11-01 10:00:00' }; it('maps them when fetched for an address with a company', () => { const address = converter.fromHiboutik({ ...hiboutikAddress(), ...details }); expect(address.taxNumber).toBe('FR123'); expect(address.companyNumber).toBe('12345678900012'); expect(address.legalStatus).toBe('SAS'); }); it('erases empty fetched values (null)', () => { const address = converter.fromHiboutik({ ...hiboutikAddress(), ...details, tax_number: '' }); expect(address.taxNumber).toBeNull(); }); it('keeps the stored ones when not fetched (undefined)', () => { const address = converter.fromHiboutik(hiboutikAddress()); expect(address.taxNumber).toBeUndefined(); expect(address.companyNumber).toBeUndefined(); expect(address.legalStatus).toBeUndefined(); }); it('erases them when the address has no company (null)', () => { const address = converter.fromHiboutik({ ...hiboutikAddress({ company: '' }), ...details }); expect(address.taxNumber).toBeNull(); expect(address.companyNumber).toBeNull(); expect(address.legalStatus).toBeNull(); }); }); });