79 lines
2.6 KiB
TypeScript
79 lines
2.6 KiB
TypeScript
import { OrderConverter } from './order.converter';
|
|
import { SaleHiboutikDto, SaleLineHiboutikDto } from '../hiboutikDTO/sale.hiboutik.dto';
|
|
|
|
const hiboutikLine = (overrides: Partial<SaleLineHiboutikDto> = {}): SaleLineHiboutikDto => ({
|
|
product_id: 746,
|
|
product_size: 1,
|
|
quantity: 2,
|
|
product_model: 'KATSEYE - WILD',
|
|
product_barcode: '2430010007467',
|
|
size_name: 'Daniela',
|
|
item_unit_gross: '17.10',
|
|
...overrides,
|
|
});
|
|
|
|
const hiboutikSale = (overrides: Partial<SaleHiboutikDto> = {}): SaleHiboutikDto => ({
|
|
sale_id: 5,
|
|
created_at: '2026-10-18 11:00:21',
|
|
completed_at: '2026-10-18 11:01:04',
|
|
customer_id: 1,
|
|
total: '34.20',
|
|
quotation: 0,
|
|
line_items: [hiboutikLine()],
|
|
...overrides,
|
|
});
|
|
|
|
describe('OrderConverter', () => {
|
|
const converter = new OrderConverter();
|
|
|
|
it('maps a completed Hiboutik sale with its lines', () => {
|
|
expect(converter.fromHiboutik(hiboutikSale())).toEqual({
|
|
hiboutikSaleId: 5,
|
|
// French summer time (UTC+2)
|
|
orderedAt: new Date('2026-10-18T09:01:04Z'),
|
|
source: 'STORE',
|
|
status: 'COMPLETED',
|
|
total: '34.20',
|
|
customer: { connect: { hiboutikId: 1 } },
|
|
lines: [
|
|
{
|
|
barcode: '2430010007467',
|
|
hiboutikProductId: 746,
|
|
hiboutikSizeId: 1,
|
|
productName: 'KATSEYE - WILD',
|
|
quantity: 2,
|
|
unitPrice: '17.10',
|
|
versionName: 'Daniela',
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it('maps a sale not completed yet as PENDING, ordered at its creation date', () => {
|
|
const order = converter.fromHiboutik(hiboutikSale({ completed_at: '0000-00-00 00:00:00' }));
|
|
expect(order.status).toBe('PENDING');
|
|
expect(order.orderedAt).toEqual(new Date('2026-10-18T09:00:21Z'));
|
|
});
|
|
|
|
it('throws when the sale has no valid date', () => {
|
|
expect(() => converter.fromHiboutik(hiboutikSale({ completed_at: '0000-00-00 00:00:00', created_at: '' }))).toThrow();
|
|
});
|
|
|
|
it('leaves an anonymous sale without customer', () => {
|
|
expect(converter.fromHiboutik(hiboutikSale({ customer_id: 0 })).customer).toBeUndefined();
|
|
});
|
|
|
|
it('uses the product name as version name and null barcode for a product without sizes', () => {
|
|
const [line] = converter.fromHiboutik(
|
|
hiboutikSale({ line_items: [hiboutikLine({ product_size: 0, size_name: '', product_barcode: '' })] }),
|
|
).lines;
|
|
expect(line.versionName).toBe('KATSEYE - WILD');
|
|
expect(line.barcode).toBeNull();
|
|
expect(line.hiboutikSizeId).toBe(0);
|
|
});
|
|
|
|
it('accepts a sale without lines', () => {
|
|
expect(converter.fromHiboutik(hiboutikSale({ line_items: [] })).lines).toEqual([]);
|
|
});
|
|
});
|