feat: Schwarmkontrolle-Protokoll

Neues SwarmControlCheck-Modul: strukturierte Weiselzellenkontrollen pro
Volk mit Zahl/Verdeckelungsstatus der Zellen, Schwarmstimmung, ergriffener
Maßnahme und optionalem naechsten Kontrolltermin.

Frontend: neue Karte auf der Volk-Detailseite, Erfassungsformular unter
/swarm-control/new sowie Quick-Add-Eintrag.
This commit is contained in:
Nick Szaunig committed 2026-08-25 09:12:50 +02:00
1 parent 4609a0f9ec
commit 1a7331b6b2
19 files changed
+1076

No files matched your search

@@ -0,0 +1,111 @@
import { NotFoundException } from '@nestjs/common';
import { SwarmControlService } from './swarm-control.service';
import { PrismaService } from '../prisma/prisma.service';
import { AuditLogService } from '../audit/audit-log.service';
describe('SwarmControlService', () => {
let service: SwarmControlService;
let prisma: {
swarmControlCheck: {
findMany: jest.Mock;
findUnique: jest.Mock;
create: jest.Mock;
update: jest.Mock;
};
};
let auditLog: { record: jest.Mock };
const check = {
id: 'check-1',
colonyId: 'colony-1',
date: new Date('2026-05-01T00:00:00.000Z'),
};
beforeEach(() => {
prisma = {
swarmControlCheck: {
findMany: jest.fn(),
findUnique: jest.fn(),
create: jest.fn(),
update: jest.fn(),
},
};
auditLog = { record: jest.fn() };
service = new SwarmControlService(
prisma as unknown as PrismaService,
auditLog as unknown as AuditLogService,
);
});
it('findById throws NotFoundException when missing', async () => {
prisma.swarmControlCheck.findUnique.mockResolvedValue(null);
await expect(service.findById('missing')).rejects.toBeInstanceOf(
NotFoundException,
);
});
it('create stores the acting user and converts date fields', async () => {
prisma.swarmControlCheck.create.mockResolvedValue(check);
await service.create(
{
colonyId: 'colony-1',
date: '2026-05-01',
nextCheckDate: '2026-05-08',
},
'user-1',
);
const [[createArg]] = prisma.swarmControlCheck.create.mock.calls as [
[
{
data: {
colonyId: string;
userId: string;
date: Date;
nextCheckDate: Date;
};
},
],
];
expect(createArg.data.colonyId).toBe('colony-1');
expect(createArg.data.userId).toBe('user-1');
expect(createArg.data.date).toBeInstanceOf(Date);
expect(createArg.data.nextCheckDate).toBeInstanceOf(Date);
});
it('update writes an audit log entry', async () => {
prisma.swarmControlCheck.findUnique.mockResolvedValue(check);
const updated = { ...check, queenCellsFound: 3, queenCellsCapped: true };
prisma.swarmControlCheck.update.mockResolvedValue(updated);
const result = await service.update(
'check-1',
{ queenCellsFound: 3, queenCellsCapped: true },
'user-1',
);
expect(result).toBe(updated);
expect(auditLog.record).toHaveBeenCalledWith(
expect.objectContaining({
entityType: 'SwarmControlCheck',
entityId: 'check-1',
action: 'UPDATE',
beforeData: check,
afterData: updated,
}),
);
});
it('findByColony orders results chronologically', async () => {
prisma.swarmControlCheck.findMany.mockResolvedValue([check]);
await service.findByColony('colony-1');
const [[queryArg]] = prisma.swarmControlCheck.findMany.mock.calls as [
[{ where: { colonyId: string }; orderBy: { date: string } }],
];
expect(queryArg.where.colonyId).toBe('colony-1');
expect(queryArg.orderBy.date).toBe('asc');
});
});