- 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.
35 lines
1.2 KiB
TypeScript
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);
|
|
});
|
|
});
|