feat(backend): Inventar (Modul 24)
EquipmentModule (GET/POST /equipment, GET/PATCH /equipment/:id) fuer Ausruestungsgegenstaende (Inventarnummer, Bezeichnung, Hersteller, Kaufdatum, Zustand, Standort, Wartungsdatum). Neues Prisma-Modell Equipment (Migration equipment).
This commit is contained in:
1 parent
f4df719df7
commit
3f20133d02
11 files changed
+410
-1
No files matched your search
@@ -0,0 +1,81 @@
|
||||
import { NotFoundException } from '@nestjs/common';
|
||||
import { EquipmentService } from './equipment.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AuditLogService } from '../audit/audit-log.service';
|
||||
|
||||
describe('EquipmentService', () => {
|
||||
let service: EquipmentService;
|
||||
let prisma: {
|
||||
equipment: {
|
||||
findMany: jest.Mock;
|
||||
findUnique: jest.Mock;
|
||||
create: jest.Mock;
|
||||
update: jest.Mock;
|
||||
};
|
||||
};
|
||||
let auditLog: { record: jest.Mock };
|
||||
|
||||
beforeEach(() => {
|
||||
prisma = {
|
||||
equipment: {
|
||||
findMany: jest.fn(),
|
||||
findUnique: jest.fn(),
|
||||
create: jest.fn(),
|
||||
update: jest.fn(),
|
||||
},
|
||||
};
|
||||
auditLog = { record: jest.fn() };
|
||||
service = new EquipmentService(
|
||||
prisma as unknown as PrismaService,
|
||||
auditLog as unknown as AuditLogService,
|
||||
);
|
||||
});
|
||||
|
||||
it('creates equipment and records an audit log entry', async () => {
|
||||
const created = {
|
||||
id: 'e1',
|
||||
inventoryNumber: 'INV-1',
|
||||
name: 'Honigschleuder',
|
||||
};
|
||||
prisma.equipment.create.mockResolvedValueOnce(created);
|
||||
|
||||
const result = await service.create(
|
||||
{ inventoryNumber: 'INV-1', name: 'Honigschleuder' },
|
||||
'user-1',
|
||||
);
|
||||
|
||||
expect(result).toEqual(created);
|
||||
expect(auditLog.record).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ entityType: 'Equipment', action: 'CREATE' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('throws NotFoundException when equipment does not exist', async () => {
|
||||
prisma.equipment.findUnique.mockResolvedValueOnce(null);
|
||||
await expect(service.findById('missing')).rejects.toBeInstanceOf(
|
||||
NotFoundException,
|
||||
);
|
||||
});
|
||||
|
||||
it('updates equipment condition and records before/after audit data', async () => {
|
||||
const before = { id: 'e1', condition: 'GOOD' };
|
||||
const after = { id: 'e1', condition: 'WORN' };
|
||||
prisma.equipment.findUnique.mockResolvedValueOnce(before);
|
||||
prisma.equipment.update.mockResolvedValueOnce(after);
|
||||
|
||||
const result = await service.update(
|
||||
'e1',
|
||||
{ condition: 'WORN' } as never,
|
||||
'user-1',
|
||||
);
|
||||
|
||||
expect(result).toEqual(after);
|
||||
expect(auditLog.record).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
action: 'UPDATE',
|
||||
beforeData: before,
|
||||
afterData: after,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user