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,61 @@
|
||||
import { NotFoundException } from '@nestjs/common';
|
||||
import { ExtractionsService } from './extractions.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AuditLogService } from '../audit/audit-log.service';
|
||||
|
||||
describe('ExtractionsService', () => {
|
||||
let service: ExtractionsService;
|
||||
let prisma: {
|
||||
extraction: { findUnique: jest.Mock };
|
||||
$transaction: jest.Mock;
|
||||
};
|
||||
let auditLog: { record: jest.Mock };
|
||||
let tx: {
|
||||
extraction: { create: jest.Mock };
|
||||
extractionHarvest: { createMany: jest.Mock };
|
||||
};
|
||||
|
||||
const extraction = { id: 'extraction-1', date: new Date() };
|
||||
|
||||
beforeEach(() => {
|
||||
tx = {
|
||||
extraction: { create: jest.fn().mockResolvedValue(extraction) },
|
||||
extractionHarvest: { createMany: jest.fn() },
|
||||
};
|
||||
prisma = {
|
||||
extraction: { findUnique: jest.fn() },
|
||||
$transaction: jest.fn((callback: (txArg: typeof tx) => unknown) =>
|
||||
callback(tx),
|
||||
),
|
||||
};
|
||||
auditLog = { record: jest.fn() };
|
||||
service = new ExtractionsService(
|
||||
prisma as unknown as PrismaService,
|
||||
auditLog as unknown as AuditLogService,
|
||||
);
|
||||
});
|
||||
|
||||
it('findById throws NotFoundException when missing', async () => {
|
||||
prisma.extraction.findUnique.mockResolvedValue(null);
|
||||
await expect(service.findById('missing')).rejects.toBeInstanceOf(
|
||||
NotFoundException,
|
||||
);
|
||||
});
|
||||
|
||||
it('create links every harvest to the extraction inside a transaction', async () => {
|
||||
prisma.extraction.findUnique.mockResolvedValue(extraction);
|
||||
|
||||
await service.create(
|
||||
{ date: '2026-07-05', harvestIds: ['harvest-1', 'harvest-2'] },
|
||||
'user-1',
|
||||
);
|
||||
|
||||
const [[createArg]] = tx.extractionHarvest.createMany.mock.calls as [
|
||||
[{ data: { extractionId: string; harvestId: string }[] }],
|
||||
];
|
||||
expect(createArg.data).toEqual([
|
||||
{ extractionId: extraction.id, harvestId: 'harvest-1' },
|
||||
{ extractionId: extraction.id, harvestId: 'harvest-2' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user