From: Jérôme Benoit Date: Thu, 16 Apr 2026 16:33:37 +0000 (+0200) Subject: test: add enum rejection tests and fix dynamic import in CLI test X-Git-Tag: cli@v4.5.0~64 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=99014cb1ccd1cef5eae6356a07cc22310619b820;p=e-mobility-charging-stations-simulator.git test: add enum rejection tests and fix dynamic import in CLI test - Add 2 edge-case tests for invalid protocol/version enum values (protocol: 'ws' and version: '2.0' are now correctly rejected) - Replace unnecessary dynamic import with static import in lifecycle.test.ts for consistency with other test files --- diff --git a/ui/cli/tests/lifecycle.test.ts b/ui/cli/tests/lifecycle.test.ts index 3f12b313..c6d54a60 100644 --- a/ui/cli/tests/lifecycle.test.ts +++ b/ui/cli/tests/lifecycle.test.ts @@ -2,6 +2,7 @@ import assert from 'node:assert' import { describe, it } from 'node:test' +import { Protocol, ProtocolVersion } from 'ui-common' import { ConnectionError } from '../src/client/errors.js' import { executeCommand } from '../src/client/lifecycle.js' @@ -36,7 +37,6 @@ await describe('lifecycle', async () => { }) await it('should reject executeCommand with NaN timeout', async () => { - const { Protocol, ProtocolVersion } = await import('ui-common') await assert.rejects( executeCommand({ config: { diff --git a/ui/common/tests/config.test.ts b/ui/common/tests/config.test.ts index 9946aab3..ab1c4e48 100644 --- a/ui/common/tests/config.test.ts +++ b/ui/common/tests/config.test.ts @@ -24,6 +24,26 @@ await describe('config schema validation', async () => { assert.strictEqual(result.success, false) }) + await it('should reject config with protocol not in Protocol enum', () => { + const result = uiServerConfigSchema.safeParse({ + host: 'localhost', + port: 8080, + protocol: 'ws', + version: '0.0.1', + }) + assert.strictEqual(result.success, false) + }) + + await it('should reject config with version not in ProtocolVersion enum', () => { + const result = uiServerConfigSchema.safeParse({ + host: 'localhost', + port: 8080, + protocol: 'ui', + version: '2.0', + }) + assert.strictEqual(result.success, false) + }) + await it('should reject missing required host field', () => { const result = uiServerConfigSchema.safeParse({ port: 8080,