feat(backend): QR-Code-System (Modul 22)
QrModule mit GET /qr/:entityType/:id.svg fuer colonies (Deep-Link direkt zu /inspections/new), apiaries, queens, honey-batches und storage-containers. Nutzt pdfkit-Nachbar qrcode zur SVG-Erzeugung.
This commit is contained in:
1 parent
a7ded02015
commit
dd88b6a92c
9 files changed
+427
-15
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import { BadRequestException, NotFoundException } from '@nestjs/common';
|
||||
import { QrService } from './qr.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
describe('QrService', () => {
|
||||
let service: QrService;
|
||||
let prisma: {
|
||||
colony: { findUnique: jest.Mock };
|
||||
apiary: { findUnique: jest.Mock };
|
||||
queen: { findUnique: jest.Mock };
|
||||
honeyBatch: { findUnique: jest.Mock };
|
||||
storageContainer: { findUnique: jest.Mock };
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
prisma = {
|
||||
colony: { findUnique: jest.fn() },
|
||||
apiary: { findUnique: jest.fn() },
|
||||
queen: { findUnique: jest.fn() },
|
||||
honeyBatch: { findUnique: jest.fn() },
|
||||
storageContainer: { findUnique: jest.fn() },
|
||||
};
|
||||
service = new QrService(prisma as unknown as PrismaService);
|
||||
});
|
||||
|
||||
it('rejects an unsupported entity type', async () => {
|
||||
await expect(service.generateSvg('unknown', 'id-1')).rejects.toBeInstanceOf(
|
||||
BadRequestException,
|
||||
);
|
||||
});
|
||||
|
||||
it('throws NotFoundException when the object does not exist', async () => {
|
||||
prisma.colony.findUnique.mockResolvedValueOnce(null);
|
||||
await expect(
|
||||
service.generateSvg('colonies', 'missing'),
|
||||
).rejects.toBeInstanceOf(NotFoundException);
|
||||
});
|
||||
|
||||
it('generates an SVG QR code for an existing colony', async () => {
|
||||
prisma.colony.findUnique.mockResolvedValueOnce({ id: 'colony-1' });
|
||||
const svg = await service.generateSvg('colonies', 'colony-1');
|
||||
expect(svg).toContain('<svg');
|
||||
});
|
||||
|
||||
it('generates an SVG QR code for an existing storage container', async () => {
|
||||
prisma.storageContainer.findUnique.mockResolvedValueOnce({ id: 'sc-1' });
|
||||
const svg = await service.generateSvg('storage-containers', 'sc-1');
|
||||
expect(svg).toContain('<svg');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user