feat(backend): Durchsichten-Modul (Modul 5)

InspectionsModule mit CRUD, Colony-Historie-Endpunkt und
Folgeaufgaben-Erstellung aus einer Durchsicht heraus.
This commit is contained in:
Nick Szaunig committed 2026-08-21 18:43:08 +02:00
1 parent 49ce23147c
commit 9b59e4bb35
10 files changed
+489 -1

No files matched your search

@@ -0,0 +1,81 @@
import { NotFoundException } from '@nestjs/common';
import { InspectionsService } from './inspections.service';
import { PrismaService } from '../prisma/prisma.service';
describe('InspectionsService', () => {
let service: InspectionsService;
let prisma: {
inspection: {
findMany: jest.Mock;
findUnique: jest.Mock;
create: jest.Mock;
};
task: { create: jest.Mock };
};
const inspection = {
id: 'inspection-1',
colonyId: 'colony-1',
date: new Date(),
};
beforeEach(() => {
prisma = {
inspection: {
findMany: jest.fn(),
findUnique: jest.fn(),
create: jest.fn(),
},
task: { create: jest.fn() },
};
service = new InspectionsService(prisma as unknown as PrismaService);
});
it('findById throws NotFoundException when missing', async () => {
prisma.inspection.findUnique.mockResolvedValue(null);
await expect(service.findById('missing')).rejects.toBeInstanceOf(
NotFoundException,
);
});
it('create stores the acting user as the inspector', async () => {
prisma.inspection.create.mockResolvedValue(inspection);
await service.create(
{ colonyId: 'colony-1', date: '2026-01-01' },
'user-1',
);
const [[createArg]] = prisma.inspection.create.mock.calls as [
[{ data: { colonyId: string; userId: string } }],
];
expect(createArg.data.colonyId).toBe('colony-1');
expect(createArg.data.userId).toBe('user-1');
});
it('createTaskFromInspection links the task to the inspection and its colony', async () => {
prisma.inspection.findUnique.mockResolvedValue(inspection);
prisma.task.create.mockResolvedValue({ id: 'task-1' });
await service.createTaskFromInspection(
'inspection-1',
{ title: 'Nachschauen' },
'user-1',
);
const [[taskArg]] = prisma.task.create.mock.calls as [
[
{
data: {
sourceInspectionId: string;
relatedType: string;
relatedId: string;
};
},
],
];
expect(taskArg.data.sourceInspectionId).toBe('inspection-1');
expect(taskArg.data.relatedType).toBe('COLONY');
expect(taskArg.data.relatedId).toBe('colony-1');
});
});