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:
@@ -202,6 +202,60 @@ describe('Employees (e2e)', () => {
|
||||
.expect(204);
|
||||
});
|
||||
|
||||
it('lists employees filtered by an array of positions', async () => {
|
||||
const suffix = Date.now().toString().slice(-6);
|
||||
const auth = { Authorization: `Bearer ${adminAccessToken}` };
|
||||
const base = {
|
||||
name: 'Ada Lovelace',
|
||||
phone: '+6281234567890',
|
||||
};
|
||||
|
||||
const sales = await request(app.getHttpServer())
|
||||
.post('/employees')
|
||||
.set(auth)
|
||||
.send({ ...base, code: `PS_${suffix}`, position: 'sales' })
|
||||
.expect(201);
|
||||
const driver = await request(app.getHttpServer())
|
||||
.post('/employees')
|
||||
.set(auth)
|
||||
.send({ ...base, code: `PD_${suffix}`, position: 'driver' })
|
||||
.expect(201);
|
||||
const crew = await request(app.getHttpServer())
|
||||
.post('/employees')
|
||||
.set(auth)
|
||||
.send({ ...base, code: `PC_${suffix}`, position: 'crew' })
|
||||
.expect(201);
|
||||
|
||||
const salesId = (sales.body as { id: string }).id;
|
||||
const driverId = (driver.body as { id: string }).id;
|
||||
const crewId = (crew.body as { id: string }).id;
|
||||
|
||||
const single = await request(app.getHttpServer())
|
||||
.get(`/employees?position=sales&code=${suffix}`)
|
||||
.set(auth)
|
||||
.expect(200);
|
||||
const singleIds = (single.body as { data: { id: string }[] }).data.map(
|
||||
(row) => row.id,
|
||||
);
|
||||
expect(singleIds).toEqual([salesId]);
|
||||
|
||||
const multi = await request(app.getHttpServer())
|
||||
.get(`/employees?position=sales&position=driver&code=${suffix}`)
|
||||
.set(auth)
|
||||
.expect(200);
|
||||
const multiIds = (multi.body as { data: { id: string }[] }).data.map(
|
||||
(row) => row.id,
|
||||
);
|
||||
expect(multiIds).toEqual(expect.arrayContaining([salesId, driverId]));
|
||||
expect(multiIds).toHaveLength(2);
|
||||
expect(multiIds).not.toContain(crewId);
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.get('/employees?position=pilot')
|
||||
.set(auth)
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it('imports employees from CSV', async () => {
|
||||
const suffix = Date.now().toString().slice(-6);
|
||||
const csv =
|
||||
|
||||
Reference in New Issue
Block a user