Config Page
This commit is contained in:
54
test/configValidate.test.js
Normal file
54
test/configValidate.test.js
Normal file
@@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
|
||||
const { validateConfig } = require('../src/configService');
|
||||
const { LIVE_SIZES } = require('../src/liveSizes');
|
||||
|
||||
const IDS = ['cam0', 'cam1', 'cam2'];
|
||||
|
||||
describe('validateConfig', () => {
|
||||
test('akzeptiert gültige Auflösung', () => {
|
||||
const r = validateConfig([{ id: 'cam0', liveSize: '320x240', stream: true }], IDS);
|
||||
expect(r.ok).toBe(true);
|
||||
expect(r.errors).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('alle erlaubten Auflösungen sind gültig', () => {
|
||||
for (const s of LIVE_SIZES) {
|
||||
expect(validateConfig([{ id: 'cam0', liveSize: s, stream: true }], IDS).ok).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
test('lehnt unbekannte id ab', () => {
|
||||
expect(validateConfig([{ id: 'camX', liveSize: '320x240', stream: true }], IDS).ok).toBe(false);
|
||||
});
|
||||
|
||||
test('lehnt ungültige Auflösung ab', () => {
|
||||
expect(validateConfig([{ id: 'cam0', liveSize: '999x999', stream: true }], IDS).ok).toBe(false);
|
||||
});
|
||||
|
||||
test('"Aus" (stream:false ohne liveSize) ist gültig', () => {
|
||||
expect(validateConfig([{ id: 'cam2', stream: false }], IDS).ok).toBe(true);
|
||||
});
|
||||
|
||||
test('stream muss boolean sein', () => {
|
||||
expect(validateConfig([{ id: 'cam0', liveSize: '320x240', stream: 'ja' }], IDS).ok).toBe(false);
|
||||
});
|
||||
|
||||
test('ein Fehler kippt das ganze Ergebnis (kein Teil-Apply)', () => {
|
||||
const r = validateConfig([
|
||||
{ id: 'cam0', liveSize: '320x240', stream: true },
|
||||
{ id: 'cam1', liveSize: 'bad', stream: true },
|
||||
], IDS);
|
||||
expect(r.ok).toBe(false);
|
||||
expect(r.errors.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('Nicht-Array → Fehler', () => {
|
||||
expect(validateConfig(undefined, IDS).ok).toBe(false);
|
||||
expect(validateConfig(null, IDS).ok).toBe(false);
|
||||
});
|
||||
|
||||
test('Eintrag ohne id → Fehler', () => {
|
||||
expect(validateConfig([{ liveSize: '320x240', stream: true }], IDS).ok).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user