import 'reflect-metadata';
import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';
import { DashboardGanttQueryDto, DashboardPeriodQueryDto } from './dashboard-query.dto';

describe('dashboard query boundaries', () => {
  it.each(['2026-02-31', '2026-07-13T00:00:00Z', '2026-7-13'])(
    'rejects invalid or non-date-only value %s',
    async (periodStart) => {
      const dto = plainToInstance(DashboardPeriodQueryDto, { periodStart });
      expect((await validate(dto)).some((error) => error.property === 'periodStart')).toBe(true);
    },
  );

  it('accepts a valid date range and bounded building name', async () => {
    const dto = plainToInstance(DashboardGanttQueryDto, {
      periodStart: '2026-07-01',
      periodEnd: '2026-07-31',
      building: 'A座',
    });
    expect(await validate(dto)).toEqual([]);
  });

  it('rejects an excessively long building name', async () => {
    const dto = plainToInstance(DashboardGanttQueryDto, { building: 'A'.repeat(51) });
    expect((await validate(dto)).some((error) => error.property === 'building')).toBe(true);
  });
});
