feat(sync): synchronize customer adresses and orders from Hiboutik sales (#1)

This commit is contained in:
2026-11-07 09:56:53 +00:00
parent 358e99c1ba
commit c91a510c56
16 changed files with 755 additions and 17 deletions

View File

@@ -0,0 +1,89 @@
import { CustomerAddressConverter } from './customerAddress.converter';
import { CustomerAddressHiboutikDto } from '../hiboutikDTO/customer.hiboutik.dto';
const hiboutikAddress = (overrides: Partial<CustomerAddressHiboutikDto> = {}): 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,
}) as CustomerAddressHiboutikDto;
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('accepts ids and flags sent as strings', () => {
const address = converter.fromHiboutik(hiboutikAddress({ address_id: '8', customers_id: '43', default: '0' } as never));
expect(address.hiboutikId).toBe(8);
expect(address.isDefault).toBe(false);
expect(address.customer).toEqual({ connect: { hiboutikId: 43 } });
});
it('erases empty optional fields (null) and defaults empty required ones to ""', () => {
const address = converter.fromHiboutik(
hiboutikAddress({ company: ' ', phone: null as unknown as string, other: '', first_name: null as unknown as string }),
);
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();
});
});
});