import 'reflect-metadata';
import { plainToInstance } from 'class-transformer';
import { CreateBookingOrderLineDto } from './create-booking-order.dto';

/**
 * Order line haz/reefer quantities arrive as JSON numbers but must default to 0
 * when omitted and coerce string inputs (defensive) to numbers.
 */
describe('CreateBookingOrderLineDto — haz/reefer coercion', () => {
  const toDto = (plain: Record<string, unknown>) =>
    plainToInstance(CreateBookingOrderLineDto, plain, {
      enableImplicitConversion: false,
      exposeDefaultValues: true,
    }) as unknown as CreateBookingOrderLineDto;

  it('defaults hazardous/reefer quantities to 0 when omitted', () => {
    const dto = toDto({ quantity: 5 });
    expect(dto.hazardousQuantity).toBe(0);
    expect(dto.reeferQuantity).toBe(0);
  });

  it('coerces provided string quantities to numbers', () => {
    const dto = toDto({ quantity: '5', hazardousQuantity: '2', reeferQuantity: '3' });
    expect(dto.quantity).toBe(5);
    expect(dto.hazardousQuantity).toBe(2);
    expect(dto.reeferQuantity).toBe(3);
  });
});
