feat(backend): Suche und Filter (Modul 14)
SearchModule mit GET /search?q= über Bienenstände, Völker, Königinnen, Aufgaben und Honigchargen. Kombinierbare Filter (Status, Standort, Bienenstand) in den bestehenden List-Endpunkten.
This commit is contained in:
1 parent
55b9bc2587
commit
146b56d683
15 files changed
+337
-27
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import { SearchService } from './search.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
describe('SearchService', () => {
|
||||
let service: SearchService;
|
||||
let prisma: {
|
||||
apiary: { findMany: jest.Mock };
|
||||
colony: { findMany: jest.Mock };
|
||||
queen: { findMany: jest.Mock };
|
||||
task: { findMany: jest.Mock };
|
||||
honeyBatch: { findMany: jest.Mock };
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
prisma = {
|
||||
apiary: { findMany: jest.fn().mockResolvedValue([]) },
|
||||
colony: { findMany: jest.fn().mockResolvedValue([]) },
|
||||
queen: { findMany: jest.fn().mockResolvedValue([]) },
|
||||
task: { findMany: jest.fn().mockResolvedValue([]) },
|
||||
honeyBatch: { findMany: jest.fn().mockResolvedValue([]) },
|
||||
};
|
||||
service = new SearchService(prisma as unknown as PrismaService);
|
||||
});
|
||||
|
||||
it('returns an empty array for a blank query', async () => {
|
||||
const results = await service.search(' ');
|
||||
expect(results).toEqual([]);
|
||||
expect(prisma.apiary.findMany).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('combines matches from every entity type', async () => {
|
||||
prisma.colony.findMany.mockResolvedValue([
|
||||
{ id: 'colony-1', code: 'V-001' },
|
||||
]);
|
||||
prisma.apiary.findMany.mockResolvedValue([
|
||||
{ id: 'apiary-1', name: 'Heimstand' },
|
||||
]);
|
||||
|
||||
const results = await service.search('V-001');
|
||||
|
||||
expect(results).toEqual(
|
||||
expect.arrayContaining([
|
||||
{ type: 'Colony', id: 'colony-1', label: 'V-001' },
|
||||
{ type: 'Apiary', id: 'apiary-1', label: 'Heimstand' },
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user