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.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user