feat(backend): Dashboard-Modul (Modul 13)
DashboardModule mit Kennzahlen-Übersicht sowie Alerts fuer überfällige Aufgaben, auffällige Völker und Lagerartikel unter Mindestbestand.
This commit is contained in:
1 parent
7ec20199d3
commit
09407d4378
7 files changed
+297
-1
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import { DashboardService } from './dashboard.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
describe('DashboardService', () => {
|
||||
let service: DashboardService;
|
||||
let prisma: {
|
||||
apiary: { count: jest.Mock };
|
||||
colony: { count: jest.Mock; findMany: jest.Mock };
|
||||
queen: { count: jest.Mock };
|
||||
task: { count: jest.Mock; findMany: jest.Mock };
|
||||
honeyBatch: { count: jest.Mock };
|
||||
stockItem: { findMany: jest.Mock };
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
prisma = {
|
||||
apiary: { count: jest.fn().mockResolvedValue(2) },
|
||||
colony: {
|
||||
count: jest.fn().mockResolvedValue(5),
|
||||
findMany: jest.fn().mockResolvedValue([]),
|
||||
},
|
||||
queen: { count: jest.fn().mockResolvedValue(4) },
|
||||
task: {
|
||||
count: jest.fn().mockResolvedValue(3),
|
||||
findMany: jest.fn().mockResolvedValue([]),
|
||||
},
|
||||
honeyBatch: { count: jest.fn().mockResolvedValue(1) },
|
||||
stockItem: { findMany: jest.fn().mockResolvedValue([]) },
|
||||
};
|
||||
service = new DashboardService(prisma as unknown as PrismaService);
|
||||
});
|
||||
|
||||
it('summary counts low-stock items below their minimum threshold', async () => {
|
||||
prisma.stockItem.findMany.mockResolvedValue([
|
||||
{ id: 'item-1', quantity: 2, minThreshold: 5 },
|
||||
{ id: 'item-2', quantity: 10, minThreshold: 5 },
|
||||
]);
|
||||
|
||||
const summary = await service.summary();
|
||||
|
||||
expect(summary.stockItemsLowCount).toBe(1);
|
||||
expect(summary.apiariesActive).toBe(2);
|
||||
expect(summary.coloniesActive).toBe(5);
|
||||
});
|
||||
|
||||
it('alerts flags overdue tasks, attention colonies, and low stock', async () => {
|
||||
prisma.task.findMany.mockResolvedValue([
|
||||
{ id: 'task-1', title: 'Beute prüfen' },
|
||||
]);
|
||||
prisma.colony.findMany.mockResolvedValue([
|
||||
{ id: 'colony-1', code: 'V-001', status: 'WEAK' },
|
||||
]);
|
||||
prisma.stockItem.findMany.mockResolvedValue([
|
||||
{ id: 'item-1', name: 'Zuckerlösung', quantity: 2, minThreshold: 5 },
|
||||
]);
|
||||
|
||||
const alerts = await service.alerts();
|
||||
|
||||
expect(alerts).toHaveLength(3);
|
||||
expect(alerts.map((alert) => alert.type)).toEqual([
|
||||
'OVERDUE_TASK',
|
||||
'COLONY_ATTENTION',
|
||||
'LOW_STOCK',
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user