import { validate } from 'class-validator';
import { CreateRentalDto } from './rental.dto';

const createRental = (overrides: Partial<CreateRentalDto> = {}) =>
  Object.assign(new CreateRentalDto(), {
    classroomId: 1,
    lesseeOrganizationId: 2,
    startDate: '2026-08-01',
    endDate: '2026-08-31',
    ...overrides,
  });

describe('classroom rental DTO boundaries', () => {
  it.each(['2026-02-31', '2026-08-01T00:00:00Z', '2026-8-1'])(
    'rejects invalid or non-date-only value %s',
    async (startDate) => {
      const errors = await validate(createRental({ startDate }));
      expect(errors.some((error) => error.property === 'startDate')).toBe(true);
    },
  );

  it.each([
    ['dailyRate', 0],
    ['totalAmount', -1],
  ] as const)('rejects non-positive %s', async (field, value) => {
    const errors = await validate(createRental({ [field]: value }));
    expect(errors.some((error) => error.property === field)).toBe(true);
  });

  it('accepts positive amounts and a leap-day date', async () => {
    await expect(
      validate(
        createRental({
          startDate: '2028-02-29',
          endDate: '2028-02-29',
          dailyRate: 0.01,
          totalAmount: 0.01,
        }),
      ),
    ).resolves.toHaveLength(0);
  });
});
