Stand_2026_12_02

This commit is contained in:
marco committed 2026-12-02 14:47:34 +01:00
1 parent 48d50e819c
commit 4c60b59150
232 files changed
+59538 -419

No files matched your search

+27
View File
@@ -1,8 +1,35 @@
import { model, Types } from 'mongoose';
import { describe, expect, it, jest } from '@jest/globals';
import { UnitsService } from './units.service';
import { UnitSchema } from '../../_schemas/anlagen/units';
import { UnitTypeDto } from '../../_dto/anlagen/units';
describe('UnitsService.findAll', () => {
it('zeigt ausschließlich Units der aktiven Anlage und liest die Auswahl nach jedem Wechsel neu', async () => {
const oldId = new Types.ObjectId(), newId = new Types.ObjectId(), emptyId = new Types.ObjectId();
let selected = oldId;
const rows = [
{ _id: new Types.ObjectId(), anlageId: oldId, name: 'Alte Unit', type: UnitTypeDto.GENERAL, components: [] },
{ _id: new Types.ObjectId(), anlageId: newId, name: 'Neue Unit', type: UnitTypeDto.GENERAL, components: [] },
];
const find = jest.fn((filter?: { anlageId: Types.ObjectId }) => ({ exec: async () => rows.filter(row => !filter || row.anlageId.equals(filter.anlageId)) }));
const service = new UnitsService({ find } as any, {} as any, {} as any,
{ getSelected: async () => ({ id: selected.toString() }) } as any);
expect((await service.findAll()).map(row => row.name)).toEqual(['Alte Unit']);
selected = newId;
expect((await service.findAll()).map(row => row.name)).toEqual(['Neue Unit']);
selected = emptyId;
expect(await service.findAll()).toEqual([]);
});
it('liefert ohne ausgewählte Anlage keine ungefilterten Daten', async () => {
const find = jest.fn();
const service = new UnitsService({ find } as any, {} as any, {} as any,
{ getSelected: async () => { throw new Error('Keine Anlage ausgewählt'); } } as any);
await expect(service.findAll()).rejects.toThrow('Keine Anlage ausgewählt');
expect(find).not.toHaveBeenCalled();
});
});
describe('UnitsService.copy', () => {
it('copies legacy components with empty names using the existing fallback', async () => {
const anlageId = new Types.ObjectId();