feat(backend): Honigchargen-Modul (Modul 11)
HoneyBatchesModule inkl. Honigmessungen und Rückverfolgbarkeits-Endpunkt, der eine Charge über die Schleuderung und Ernte bis zu den Ursprungsvölkern zurückverfolgt.
This commit is contained in:
1 parent
5c2c0608d1
commit
cf625552d1
9 files changed
+474
-1
No files matched your search
@@ -0,0 +1,98 @@
|
||||
import { NotFoundException } from '@nestjs/common';
|
||||
import { HoneyBatchesService } from './honey-batches.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AuditLogService } from '../audit/audit-log.service';
|
||||
|
||||
describe('HoneyBatchesService', () => {
|
||||
let service: HoneyBatchesService;
|
||||
let prisma: {
|
||||
honeyBatch: {
|
||||
findMany: jest.Mock;
|
||||
findUnique: jest.Mock;
|
||||
create: jest.Mock;
|
||||
};
|
||||
honeyMeasurement: { create: jest.Mock };
|
||||
};
|
||||
let auditLog: { record: jest.Mock };
|
||||
|
||||
const extraction = {
|
||||
id: 'extraction-1',
|
||||
date: new Date(),
|
||||
room: 'Raum 1',
|
||||
harvests: [
|
||||
{
|
||||
harvest: {
|
||||
id: 'harvest-1',
|
||||
date: new Date(),
|
||||
apiaryId: 'apiary-1',
|
||||
colonies: [{ colony: { id: 'colony-1', code: 'V-001' } }],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
const honeyBatch = {
|
||||
id: 'batch-1',
|
||||
batchNumber: 'HC-2026-001',
|
||||
honeyType: 'Blütenhonig',
|
||||
amount: 20,
|
||||
status: 'RAW',
|
||||
measurements: [],
|
||||
extraction,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
prisma = {
|
||||
honeyBatch: {
|
||||
findMany: jest.fn(),
|
||||
findUnique: jest.fn(),
|
||||
create: jest.fn(),
|
||||
},
|
||||
honeyMeasurement: { create: jest.fn() },
|
||||
};
|
||||
auditLog = { record: jest.fn() };
|
||||
service = new HoneyBatchesService(
|
||||
prisma as unknown as PrismaService,
|
||||
auditLog as unknown as AuditLogService,
|
||||
);
|
||||
});
|
||||
|
||||
it('findById throws NotFoundException when missing', async () => {
|
||||
prisma.honeyBatch.findUnique.mockResolvedValue(null);
|
||||
await expect(service.findById('missing')).rejects.toBeInstanceOf(
|
||||
NotFoundException,
|
||||
);
|
||||
});
|
||||
|
||||
it('create stores the batch and returns it with relations', async () => {
|
||||
prisma.honeyBatch.create.mockResolvedValue(honeyBatch);
|
||||
prisma.honeyBatch.findUnique.mockResolvedValue(honeyBatch);
|
||||
|
||||
await service.create(
|
||||
{ batchNumber: 'HC-2026-001', extractionId: 'extraction-1' },
|
||||
'user-1',
|
||||
);
|
||||
|
||||
const [[createArg]] = prisma.honeyBatch.create.mock.calls as [
|
||||
[{ data: { batchNumber: string; extractionId: string } }],
|
||||
];
|
||||
expect(createArg.data.batchNumber).toBe('HC-2026-001');
|
||||
expect(createArg.data.extractionId).toBe('extraction-1');
|
||||
});
|
||||
|
||||
it('traceability flattens the extraction, harvest, and colony chain', async () => {
|
||||
prisma.honeyBatch.findUnique.mockResolvedValue(honeyBatch);
|
||||
|
||||
const result = await service.traceability('batch-1');
|
||||
|
||||
expect(result.honeyBatch.batchNumber).toBe('HC-2026-001');
|
||||
expect(result.extraction.id).toBe('extraction-1');
|
||||
expect(result.harvests).toEqual([
|
||||
{
|
||||
id: 'harvest-1',
|
||||
date: extraction.harvests[0].harvest.date,
|
||||
apiaryId: 'apiary-1',
|
||||
colonies: [{ id: 'colony-1', code: 'V-001' }],
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user