feat: warn on the dashboard when a swarm check is overdue

Schwarmkontrolle already captures nextCheckDate per check, but it was
only ever visible by opening that one colony's tab. During swarm
season a missed follow-up check can mean losing half the colony, so
this now surfaces as a dashboard alert (OVERDUE_SWARM_CHECK) like
overdue tasks already do - only the most recent check per colony is
considered, so a completed follow-up clears the warning.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
Nick SzaunigandClaude Sonnet 5 committed 2026-09-06 02:35:17 +02:00
1 parent acbf5f16ce
commit 0881a38800
4 files changed
+101 -16

No files matched your search

@@ -10,6 +10,7 @@ describe('DashboardService', () => {
task: { count: jest.Mock; findMany: jest.Mock };
honeyBatch: { count: jest.Mock };
stockItem: { findMany: jest.Mock };
swarmControlCheck: { findMany: jest.Mock };
};
beforeEach(() => {
@@ -26,6 +27,7 @@ describe('DashboardService', () => {
},
honeyBatch: { count: jest.fn().mockResolvedValue(1) },
stockItem: { findMany: jest.fn().mockResolvedValue([]) },
swarmControlCheck: { findMany: jest.fn().mockResolvedValue([]) },
};
service = new DashboardService(prisma as unknown as PrismaService);
});
@@ -63,4 +65,46 @@ describe('DashboardService', () => {
'LOW_STOCK',
]);
});
it('flags a colony whose most recent swarm check is overdue', async () => {
prisma.swarmControlCheck.findMany.mockResolvedValue([
{
colonyId: 'colony-1',
nextCheckDate: new Date('2020-01-01'),
colony: { code: 'V-001' },
},
]);
const alerts = await service.alerts();
expect(alerts).toEqual([
{
type: 'OVERDUE_SWARM_CHECK',
message: 'Schwarmkontrolle für Volk V-001 überfällig',
relatedType: 'Colony',
relatedId: 'colony-1',
},
]);
});
it('ignores an overdue swarm check when a newer check already superseded it', async () => {
prisma.swarmControlCheck.findMany.mockResolvedValue([
{
colonyId: 'colony-1',
date: new Date('2026-06-10'),
nextCheckDate: null,
colony: { code: 'V-001' },
},
{
colonyId: 'colony-1',
date: new Date('2026-06-01'),
nextCheckDate: new Date('2020-01-01'),
colony: { code: 'V-001' },
},
]);
const alerts = await service.alerts();
expect(alerts).toHaveLength(0);
});
});