import { plainToInstance } from 'class-transformer'; import { validate } from 'class-validator'; import { ListEmployeesQueryDto } from './employee.dto'; describe('ListEmployeesQueryDto', () => { it('coerces a single position query value into an array', async () => { const dto = plainToInstance(ListEmployeesQueryDto, { position: 'sales' }); expect(dto.position).toEqual(['sales']); expect(await validate(dto)).toHaveLength(0); }); it('accepts multiple positions', async () => { const dto = plainToInstance(ListEmployeesQueryDto, { position: ['sales', 'driver'], }); expect(dto.position).toEqual(['sales', 'driver']); expect(await validate(dto)).toHaveLength(0); }); it('rejects an invalid position in the array', async () => { const dto = plainToInstance(ListEmployeesQueryDto, { position: ['pilot'], }); expect(await validate(dto)).not.toHaveLength(0); }); it('drops empty entries and deduplicates positions', async () => { const dto = plainToInstance(ListEmployeesQueryDto, { position: ['sales', '', 'sales'], }); expect(dto.position).toEqual(['sales']); expect(await validate(dto)).toHaveLength(0); }); });