import 'reflect-metadata';
import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';
import { BatchRoomExpenseDto } from './expense.dto';

describe('BatchRoomExpenseDto boundaries', () => {
  it.each([
    { expenses: [] },
    { expenses: [{ roomId: 1, expenseType: 'water', amount: 0 }] },
    { expenses: [{ roomId: 1, expenseType: 'water', amount: -1 }] },
    { expenses: [{ roomId: 1, expenseType: 'water', amount: 1.001 }] },
    { periodStart: '2026-02-31' },
  ])('rejects invalid batch payload %#', async (override) => {
    const dto = plainToInstance(BatchRoomExpenseDto, {
      periodStart: '2026-07-01',
      periodEnd: '2026-07-31',
      expenses: [{ roomId: 1, expenseType: 'water', amount: 10 }],
      ...override,
    });
    await expect(validate(dto)).resolves.not.toHaveLength(0);
  });

  it('accepts a valid batch payload', async () => {
    const dto = plainToInstance(BatchRoomExpenseDto, {
      periodStart: '2026-07-01',
      periodEnd: '2026-07-31',
      expenses: [{ roomId: 1, expenseType: 'water', amount: 10.25 }],
    });
    await expect(validate(dto)).resolves.toHaveLength(0);
  });
});
