Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
453 changes: 453 additions & 0 deletions apps/api-e2e/src/api/project-activities.e2e.spec.ts

Large diffs are not rendered by default.

134 changes: 100 additions & 34 deletions apps/api-e2e/src/api/projects.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { randomUUID } from 'node:crypto';
import {
createTestApp,
login,
Expand Down Expand Up @@ -67,6 +68,7 @@ describe('Projects — CRUD, service orders, assignment matrix', () => {
expect(created.body.code).toBe('P-1');
expect(created.body.isActive).toBe(true);
expect(created.body.assignedEmployeeCount).toBe(0);
expect(created.body.activityCount).toBe(0);
});

it('HRAdmin may create; duplicate codes are rejected with 409', async () => {
Expand Down Expand Up @@ -381,53 +383,117 @@ describe('Projects — CRUD, service orders, assignment matrix', () => {
expect(res.body.serviceOrders[0].bookedMinutes).toBe(120);
});

it('project report lists activities for Manager/HRAdmin only', async () => {
const { manager, worker } = await fixture();
it('project report prefers catalog names and keeps legacy activities and gross hours for Manager/HRAdmin only', async () => {
const { hr, manager, worker } = await fixture();
const managerToken = await login(ctx.http, manager.email);
const hrToken = await login(ctx.http, hr.email);
const workerToken = await login(ctx.http, worker.email);
const project = await seedProject(ctx.prisma, {
code: 'P-REPORT',
name: 'Customer project',
assigneeIds: [worker.id],
serviceOrders: [{ orderNo: 'SA-1', title: 'Beratung' }],
});
const order = project.serviceOrders[0];
const clockIn = new Date(Date.now() - 3 * 60 * 60 * 1000);
await ctx.prisma.timeEntry.create({
data: {
employeeId: worker.id,
clockIn,
clockOut: new Date(clockIn.getTime() + 90 * 60 * 1000),
status: 'Approved',
projectId: project.id,
serviceOrderId: order.id,
activity: 'Kundentermin vorbereitet',
},
const entry = { employeeId: worker.id, projectId: project.id };
const catalog = await ctx.prisma.activity.create({
data: { projectId: project.id, name: 'Original catalog name' },
});
const next = await ctx.prisma.activity.create({
data: { projectId: project.id, name: 'Packen' },
});
const captureGroupId = randomUUID();
const day = '2026-07-01';
const at = (time: string) => new Date(`${day}T${time}+02:00`);
await ctx.prisma.timeEntry.createMany({
data: [
{
...entry,
clockIn: at('08:00:00'),
clockOut: at('12:00:30'),
status: 'Approved',
source: 'Terminal',
captureGroupId,
activityId: catalog.id,
activity: 'Old free text',
},
{
...entry,
clockIn: at('12:00:30'),
clockOut: at('16:00:00'),
status: 'Pending',
source: 'Terminal',
captureGroupId,
activityId: next.id,
},
],
});
const catalogName = 'Sortieren, prüfen; "Süd"';
await ctx.prisma.activity.update({
where: { id: catalog.id },
data: { name: catalogName, isActive: false },
});
const order = await ctx.prisma.serviceOrder.create({
data: { projectId: project.id, orderNo: 'SA-1', title: 'Beratung' },
});
const freeText = 'Kundentermin vorbereitet';
await ctx.prisma.timeEntry.createMany({
data: [
{
...entry,
clockIn: at('16:30:00'),
clockOut: at('18:00:00'),
serviceOrderId: order.id,
status: 'Approved',
activity: freeText,
},
{
...entry,
clockIn: at('18:00:00'),
clockOut: at('18:30:00'),
serviceOrderId: order.id,
status: 'Approved',
},
],
});

await ctx.http.get(`/api/projects/${project.id}/report`).expect(401);
const report = `/api/projects/${project.id}/report`;
await ctx.http.get(report).expect(401);
await ctx.http
.get(`/api/projects/${project.id}/report`)
.set('Authorization', `Bearer ${workerToken}`)
.get(report)
.auth(workerToken, { type: 'bearer' })
.expect(403);
const res = await ctx.http
.get(`/api/projects/${project.id}/report`)
.set('Authorization', `Bearer ${managerToken}`)
.expect(200);
expect(res.body.projectCode).toBe('P-REPORT');
expect(res.body.rows.length).toBe(1);
expect(res.body.rows[0].employeeName).toBe('Willi Worker');
expect(res.body.rows[0].orderNo).toBe('SA-1');
expect(res.body.rows[0].grossMinutes).toBe(90);
expect(res.body.rows[0].activity).toBe('Kundentermin vorbereitet');
expect(res.body.totalGrossMinutes).toBe(90);
const row = { date: day, employeeName: 'Willi Worker' };
const noOrder = { orderNo: null, orderTitle: null };
const withOrder = { orderNo: order.orderNo, orderTitle: order.title };
for (const token of [managerToken, hrToken]) {
const res = await ctx.http
.get(report)
.auth(token, { type: 'bearer' })
.expect(200);
expect(res.body).toEqual({
projectCode: project.code,
projectName: project.name,
from: null,
to: null,
rows: [
{ ...row, ...noOrder, grossMinutes: 240.5, activity: catalogName },
{ ...row, ...noOrder, grossMinutes: 239.5, activity: next.name },
{ ...row, ...withOrder, grossMinutes: 90, activity: freeText },
{ ...row, ...withOrder, grossMinutes: 30, activity: null },
],
totalGrossMinutes: 600,
});
}

// A window in the past excludes the entry.
const filtered = await ctx.http
.get(
`/api/projects/${project.id}/report?from=2000-01-01T00:00:00.000Z&to=2000-12-31T00:00:00.000Z`,
)
.set('Authorization', `Bearer ${managerToken}`)
.get(report)
.auth(managerToken, { type: 'bearer' })
.query({
from: '2000-01-01T00:00:00.000Z',
to: '2000-12-31T00:00:00.000Z',
})
.expect(200);
expect(filtered.body.rows.length).toBe(0);
expect(filtered.body.rows).toEqual([]);
expect(filtered.body.totalGrossMinutes).toBe(0);
});
});
46 changes: 46 additions & 0 deletions apps/api-e2e/src/api/solo-time.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,52 @@ describe('Solo working-time actions', () => {
.expect(201);
});

it('preserves a historical catalog activity on correction unless its project changes', async () => {
const { owner, auth } = await fixture();
const project = await seedProject(ctx.prisma, {
code: 'HISTORICAL',
assigneeIds: [owner.id],
});
const activity = await ctx.prisma.activity.create({
data: { projectId: project.id, name: 'Catalog activity' },
});
const created = await ctx.http
.post('/api/timeentries/manual')
.set('Authorization', auth)
.send({ ...interval, projectId: project.id, activity: 'Historical text' })
.expect(201);
const id: string = created.body.id;
await ctx.prisma.timeEntry.update({
where: { id },
data: { activityId: activity.id },
});

const same = await ctx.http
.patch(`/api/timeentries/${id}/correct`)
.set('Authorization', auth)
.send({ ...interval, revision: 0, reason: 'Retain project' })
.expect(200);
expect(same.body).toMatchObject({
projectId: project.id,
activityId: activity.id,
catalogActivityName: activity.name,
activity: 'Historical text',
});

const unassigned = await ctx.http
.patch(`/api/timeentries/${id}/correct`)
.set('Authorization', auth)
.send({ ...interval, revision: 1, reason: 'Unassign', projectId: null })
.expect(200);
expect(unassigned.body).toMatchObject({
...interval,
projectId: null,
activityId: null,
catalogActivityName: null,
activity: 'Historical text',
});
});

it('serializes concurrent manual inserts and does not create a losing audit row', async () => {
const { auth } = await fixture();
const responses = await Promise.all(
Expand Down
Loading