feat(backend): Fütterungen-Modul (Modul 9)
FeedingsModule mit Erfassung, Colony-Historie und Mengensummen-Endpunkt je Einheit.
This commit is contained in:
1 parent
1f71ac9e3c
commit
cc0aaf0a31
9 files changed
+382
-1
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import { NotFoundException } from '@nestjs/common';
|
||||
import { FeedingsService } from './feedings.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AuditLogService } from '../audit/audit-log.service';
|
||||
|
||||
describe('FeedingsService', () => {
|
||||
let service: FeedingsService;
|
||||
let prisma: {
|
||||
feeding: {
|
||||
findMany: jest.Mock;
|
||||
findUnique: jest.Mock;
|
||||
create: jest.Mock;
|
||||
groupBy: jest.Mock;
|
||||
};
|
||||
};
|
||||
let auditLog: { record: jest.Mock };
|
||||
|
||||
const feeding = { id: 'feeding-1', colonyId: 'colony-1', date: new Date() };
|
||||
|
||||
beforeEach(() => {
|
||||
prisma = {
|
||||
feeding: {
|
||||
findMany: jest.fn(),
|
||||
findUnique: jest.fn(),
|
||||
create: jest.fn(),
|
||||
groupBy: jest.fn(),
|
||||
},
|
||||
};
|
||||
auditLog = { record: jest.fn() };
|
||||
service = new FeedingsService(
|
||||
prisma as unknown as PrismaService,
|
||||
auditLog as unknown as AuditLogService,
|
||||
);
|
||||
});
|
||||
|
||||
it('findById throws NotFoundException when missing', async () => {
|
||||
prisma.feeding.findUnique.mockResolvedValue(null);
|
||||
await expect(service.findById('missing')).rejects.toBeInstanceOf(
|
||||
NotFoundException,
|
||||
);
|
||||
});
|
||||
|
||||
it('create stores the acting user as the feeder', async () => {
|
||||
prisma.feeding.create.mockResolvedValue(feeding);
|
||||
|
||||
await service.create(
|
||||
{
|
||||
colonyId: 'colony-1',
|
||||
date: '2026-01-01',
|
||||
feedType: 'SUGAR_WATER',
|
||||
amount: 2,
|
||||
unit: 'l',
|
||||
},
|
||||
'user-1',
|
||||
);
|
||||
|
||||
const [[createArg]] = prisma.feeding.create.mock.calls as [
|
||||
[{ data: { colonyId: string; userId: string } }],
|
||||
];
|
||||
expect(createArg.data.colonyId).toBe('colony-1');
|
||||
expect(createArg.data.userId).toBe('user-1');
|
||||
});
|
||||
|
||||
it('summaryByColony sums amounts per unit', async () => {
|
||||
prisma.feeding.groupBy.mockResolvedValue([
|
||||
{ unit: 'l', _sum: { amount: 5.5 } },
|
||||
]);
|
||||
|
||||
const summary = await service.summaryByColony('colony-1');
|
||||
|
||||
expect(summary).toEqual([{ unit: 'l', totalAmount: 5.5 }]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user