Files
trackgo-be/src/modules/configuration/employees/dto/employee.dto.spec.ts
T
shancheas 627aeac4a0 Add API documentation for TrackGo HTTP API and enhance employee management features
- Created a new `api.md` file detailing the TrackGo HTTP API, including authentication, user management, and employee operations.
- Updated `Employee` type to simplify user relation handling by replacing `UserRelation` with a more concise structure.
- Enhanced filtering capabilities in employee queries to support an array of positions.
- Refactored employee-related services and repositories to accommodate the new position filtering logic.
- Added unit and e2e tests to validate the new API documentation and employee management functionalities.
2026-08-27 15:07:20 +07:00

35 lines
1.2 KiB
TypeScript

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);
});
});