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
4 changes: 4 additions & 0 deletions apps/api-e2e/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ module.exports = {
transform: {
'^.+\\.[tj]s$': ['@swc/jest', swcJestConfig],
},
moduleNameMapper: {
'^shared$': '<rootDir>/../../libs/shared/src/index.ts',
'^(\\.{1,2}/.*)\\.js$': '$1',
},
moduleFileExtensions: ['ts', 'js', 'html'],
testTimeout: 30000,
coverageDirectory: 'test-output/jest/coverage',
Expand Down
71 changes: 64 additions & 7 deletions apps/api-e2e/src/api/absences.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { createTestApp, login, seedEmployee, type TestContext } from '../support/test-app';
import {
createTestApp,
login,
seedEmployee,
type TestContext,
} from '../support/test-app';

describe('Absences — Sickness / Training / Flextime', () => {
let ctx: TestContext;
Expand All @@ -23,11 +28,21 @@ describe('Absences — Sickness / Training / Flextime', () => {

const today = new Date().toISOString();
const tomorrow = new Date(Date.now() + 86_400_000).toISOString();
const dayAfterTomorrow = new Date(
Date.now() + 2 * 86_400_000,
).toISOString();
const threeDaysOut = new Date(Date.now() + 3 * 86_400_000).toISOString();

const sickness = await ctx.http
.post('/api/absences')
.set('Authorization', `Bearer ${token}`)
.send({ employeeId: anna.id, kind: 'Sickness', from: today, to: today, certified: true })
.send({
employeeId: anna.id,
kind: 'Sickness',
from: today,
to: today,
certified: true,
})
.expect(201);
expect(sickness.body).toMatchObject({ kind: 'Sickness', certified: true });

Expand All @@ -37,25 +52,35 @@ describe('Absences — Sickness / Training / Flextime', () => {
.send({
employeeId: anna.id,
kind: 'Training',
from: today,
to: tomorrow,
from: tomorrow,
to: dayAfterTomorrow,
note: 'NestJS Schulung',
})
.expect(201);
expect(training.body).toMatchObject({ kind: 'Training', note: 'NestJS Schulung' });
expect(training.body).toMatchObject({
kind: 'Training',
note: 'NestJS Schulung',
});

const flextime = await ctx.http
.post('/api/absences')
.set('Authorization', `Bearer ${token}`)
.send({ employeeId: anna.id, kind: 'Flextime', from: tomorrow, to: tomorrow })
.send({
employeeId: anna.id,
kind: 'Flextime',
from: threeDaysOut,
to: threeDaysOut,
})
.expect(201);
expect(flextime.body).toMatchObject({ kind: 'Flextime' });

const list = await ctx.http
.get(`/api/absences?employeeId=${anna.id}`)
.set('Authorization', `Bearer ${token}`)
.expect(200);
const kinds = (list.body as Array<{ kind: string }>).map((a) => a.kind).sort();
const kinds = (list.body as Array<{ kind: string }>)
.map((a) => a.kind)
.sort();
expect(kinds).toEqual(['Flextime', 'Sickness', 'Training']);
});

Expand All @@ -79,4 +104,36 @@ describe('Absences — Sickness / Training / Flextime', () => {
})
.expect(400);
});

it('rejects overlapping absences for the same employee', async () => {
const anna = await seedEmployee(ctx.prisma, {
personalNo: '1001',
firstName: 'Anna',
lastName: 'Mueller',
email: 'anna@test.local',
});
const token = await login(ctx.http, 'anna@test.local');
const first = {
employeeId: anna.id,
kind: 'Sickness',
from: '2026-09-07T00:00:00.000Z',
to: '2026-09-09T00:00:00.000Z',
};

await ctx.http
.post('/api/absences')
.set('Authorization', `Bearer ${token}`)
.send(first)
.expect(201);
await ctx.http
.post('/api/absences')
.set('Authorization', `Bearer ${token}`)
.send({
employeeId: anna.id,
kind: 'Training',
from: '2026-09-09T00:00:00.000Z',
to: '2026-09-10T00:00:00.000Z',
})
.expect(409);
});
});
Loading