feat(backend): Ernten- und Schleuderungs-Module (Modul 10)
HarvestsModule und ExtractionsModule als Fundament der Rückverfolgbarkeitskette: eine Ernte kann mehrere Völker umfassen, eine Schleuderung mehrere Ernten zusammenführen.
This commit is contained in:
1 parent
d71785d531
commit
340397b34d
14 files changed
+705
-1
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { NotFoundException } from '@nestjs/common';
|
||||
import { HarvestsService } from './harvests.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AuditLogService } from '../audit/audit-log.service';
|
||||
|
||||
describe('HarvestsService', () => {
|
||||
let service: HarvestsService;
|
||||
let prisma: {
|
||||
harvest: { findUnique: jest.Mock };
|
||||
$transaction: jest.Mock;
|
||||
};
|
||||
let auditLog: { record: jest.Mock };
|
||||
let tx: {
|
||||
harvest: { create: jest.Mock };
|
||||
harvestColony: { createMany: jest.Mock };
|
||||
};
|
||||
|
||||
const harvest = { id: 'harvest-1', apiaryId: 'apiary-1', date: new Date() };
|
||||
|
||||
beforeEach(() => {
|
||||
tx = {
|
||||
harvest: { create: jest.fn().mockResolvedValue(harvest) },
|
||||
harvestColony: { createMany: jest.fn() },
|
||||
};
|
||||
prisma = {
|
||||
harvest: { findUnique: jest.fn() },
|
||||
$transaction: jest.fn((callback: (txArg: typeof tx) => unknown) =>
|
||||
callback(tx),
|
||||
),
|
||||
};
|
||||
auditLog = { record: jest.fn() };
|
||||
service = new HarvestsService(
|
||||
prisma as unknown as PrismaService,
|
||||
auditLog as unknown as AuditLogService,
|
||||
);
|
||||
});
|
||||
|
||||
it('findById throws NotFoundException when missing', async () => {
|
||||
prisma.harvest.findUnique.mockResolvedValue(null);
|
||||
await expect(service.findById('missing')).rejects.toBeInstanceOf(
|
||||
NotFoundException,
|
||||
);
|
||||
});
|
||||
|
||||
it('create links every colony to the harvest inside a transaction', async () => {
|
||||
prisma.harvest.findUnique.mockResolvedValue(harvest);
|
||||
|
||||
await service.create(
|
||||
{
|
||||
apiaryId: 'apiary-1',
|
||||
date: '2026-07-01',
|
||||
colonyIds: ['colony-1', 'colony-2'],
|
||||
},
|
||||
'user-1',
|
||||
);
|
||||
|
||||
const [[createArg]] = tx.harvestColony.createMany.mock.calls as [
|
||||
[{ data: { harvestId: string; colonyId: string }[] }],
|
||||
];
|
||||
expect(createArg.data).toEqual([
|
||||
{ harvestId: harvest.id, colonyId: 'colony-1' },
|
||||
{ harvestId: harvest.id, colonyId: 'colony-2' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user