]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
test: add enum rejection tests and fix dynamic import in CLI test
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 16 Apr 2026 16:33:37 +0000 (18:33 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 16 Apr 2026 16:33:37 +0000 (18:33 +0200)
- 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

ui/cli/tests/lifecycle.test.ts
ui/common/tests/config.test.ts

index 3f12b313502951c02036207421325cfd99e3cf18..c6d54a601d47d8eb7b60c27100855fc68da9a788 100644 (file)
@@ -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: {
index 9946aab379d7983edf14a19d8fb56f808a3e4237..ab1c4e487a06239ef56b1515853adb0a5a8b1ee5 100644 (file)
@@ -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,