From 9693a6751df1434a3788ffd2699540946509e232 Mon Sep 17 00:00:00 2001 From: PaulDalek Date: Wed, 11 Dec 2024 11:01:30 +0100 Subject: [PATCH] Tests for the WebSocket options. --- tests/unit/validation/cli.test.js | 49 ++++++++++++++++++++++++++++ tests/unit/validation/config.test.js | 49 ++++++++++++++++++++++++++++ tests/unit/validation/envs.test.js | 36 ++++++++++++++++++++ tests/unit/validation/shared.js | 39 ++++++++++++++++++++++ 4 files changed, 173 insertions(+) diff --git a/tests/unit/validation/cli.test.js b/tests/unit/validation/cli.test.js index df90c4f..1b64d5e 100644 --- a/tests/unit/validation/cli.test.js +++ b/tests/unit/validation/cli.test.js @@ -267,6 +267,19 @@ describe('CLI options should be correctly parsed and validated', () => { debuggingPort: 9222 }); + // webSocket + tests.webSocket('webSocket', { + enable: false, + reconnect: false, + rejectUnauthorized: false, + pingTimeout: 16000, + reconnectInterval: 3000, + reconnectAttempts: 3, + messageInterval: 3600000, + gatherAllOptions: false, + url: null + }); + // payload tests.payload('payload', { requestId: 'd4faa416-0e85-433a-9f84-e735567d8fa5' @@ -658,6 +671,42 @@ describe('Debug configuration options should be correctly parsed and validated', tests.debugDebuggingPort('debuggingPort'); }); +describe('WebSocket configuration options should be correctly parsed and validated', () => { + // Return config tests with a specific schema and strictCheck flag injected + const tests = configTests(LooseConfigSchema.shape.webSocket, false); + + // webSocket.enable + tests.webSocketEnable('enable'); + + // webSocket.reconnect + tests.webSocketReconnect('reconnect'); + + // webSocket.rejectUnauthorized + tests.webSocketRejectUnauthorized('rejectUnauthorized'); + + // webSocket.pingTimeout + tests.webSocketPingTimeout('pingTimeout'); + + // webSocket.reconnectInterval + tests.webSocketReconnectInterval('reconnectInterval'); + + // webSocket.reconnectAttempts + tests.webSocketReconnectAttempts('reconnectAttempts'); + + // webSocket.messageInterval + tests.webSocketMessageInterval('messageInterval'); + + // webSocket.gatherAllOptions + tests.webSocketGatherAllOptions('gatherAllOptions'); + + // webSocket.url + tests.webSocketUrl( + 'url', + ['ws://example.com', 'wss://example.com'], + ['ws:a.com', 'ws:/b.com', 'wss:c.com', 'wss:/d.com'] + ); +}); + describe('Payload configuration options should be correctly parsed and validated', () => { // Return config tests with a specific schema and strictCheck flag injected const tests = configTests(LooseConfigSchema.shape.payload, false); diff --git a/tests/unit/validation/config.test.js b/tests/unit/validation/config.test.js index 72890cd..105e2f8 100644 --- a/tests/unit/validation/config.test.js +++ b/tests/unit/validation/config.test.js @@ -267,6 +267,19 @@ describe('Configuration options should be correctly parsed and validated', () => debuggingPort: 9222 }); + // webSocket + tests.webSocket('webSocket', { + enable: false, + reconnect: false, + rejectUnauthorized: false, + pingTimeout: 16000, + reconnectInterval: 3000, + reconnectAttempts: 3, + messageInterval: 3600000, + gatherAllOptions: false, + url: null + }); + // payload tests.payload('payload', { requestId: 'd4faa416-0e85-433a-9f84-e735567d8fa5' @@ -669,6 +682,42 @@ describe('Debug configuration options should be correctly parsed and validated', tests.debugDebuggingPort('debuggingPort'); }); +describe('WebSocket configuration options should be correctly parsed and validated', () => { + // Return config tests with a specific schema and strictCheck flag injected + const tests = configTests(StrictConfigSchema.shape.webSocket, true); + + // webSocket.enable + tests.webSocketEnable('enable'); + + // webSocket.reconnect + tests.webSocketReconnect('reconnect'); + + // webSocket.rejectUnauthorized + tests.webSocketRejectUnauthorized('rejectUnauthorized'); + + // webSocket.pingTimeout + tests.webSocketPingTimeout('pingTimeout'); + + // webSocket.reconnectInterval + tests.webSocketReconnectInterval('reconnectInterval'); + + // webSocket.reconnectAttempts + tests.webSocketReconnectAttempts('reconnectAttempts'); + + // webSocket.messageInterval + tests.webSocketMessageInterval('messageInterval'); + + // webSocket.gatherAllOptions + tests.webSocketGatherAllOptions('gatherAllOptions'); + + // webSocket.url + tests.webSocketUrl( + 'url', + ['ws://example.com', 'wss://example.com'], + ['ws:a.com', 'ws:/b.com', 'wss:c.com', 'wss:/d.com'] + ); +}); + describe('Payload configuration options should be correctly parsed and validated', () => { // Return config tests with a specific schema and strictCheck flag injected const tests = configTests(StrictConfigSchema.shape.payload, true); diff --git a/tests/unit/validation/envs.test.js b/tests/unit/validation/envs.test.js index 1b428e2..5a1d0bb 100644 --- a/tests/unit/validation/envs.test.js +++ b/tests/unit/validation/envs.test.js @@ -339,3 +339,39 @@ describe('DEBUG environment variables should be correctly parsed and validated', // DEBUG_DEBUGGING_PORT tests.debugDebuggingPort('DEBUG_DEBUGGING_PORT'); }); + +describe('WEB_SOCKET environment variables should be correctly parsed and validated', () => { + // WEB_SOCKET_ENABLE + tests.webSocketEnable('WEB_SOCKET_ENABLE'); + + // WEB_SOCKET_RECONNECT + tests.webSocketReconnect('WEB_SOCKET_RECONNECT'); + + // WEB_SOCKET_REJECT_UNAUTHORIZED + tests.webSocketRejectUnauthorized('WEB_SOCKET_REJECT_UNAUTHORIZED'); + + // WEB_SOCKET_PING_TIMEOUT + tests.webSocketPingTimeout('WEB_SOCKET_PING_TIMEOUT'); + + // WEB_SOCKET_RECONNECT_INTERVAL + tests.webSocketReconnectInterval('WEB_SOCKET_RECONNECT_INTERVAL'); + + // WEB_SOCKET_RECONNECT_ATTEMPTS + tests.webSocketReconnectAttempts('WEB_SOCKET_RECONNECT_ATTEMPTS'); + + // WEB_SOCKET_MESSAGE_INTERVAL + tests.webSocketMessageInterval('WEB_SOCKET_MESSAGE_INTERVAL'); + + // WEB_SOCKET_GATHER_ALL_OPTIONS + tests.webSocketGatherAllOptions('WEB_SOCKET_GATHER_ALL_OPTIONS'); + + // WEB_SOCKET_URL + tests.webSocketUrl( + 'WEB_SOCKET_URL', + ['ws://example.com/socket', 'wss://example.com/socket'], + ['example.com', 'ws:a.com', 'ws:/b.com', 'wss:c.com', 'wss:/d.com'] + ); + + // WEB_SOCKET_SECRET + tests.webSocketSecret('WEB_SOCKET_SECRET'); +}); diff --git a/tests/unit/validation/shared.js b/tests/unit/validation/shared.js index 2f0a015..65a4ed3 100644 --- a/tests/unit/validation/shared.js +++ b/tests/unit/validation/shared.js @@ -2555,6 +2555,45 @@ export function configTests(schema, strictCheck) { debugDebuggingPort: (property) => { describe(property, () => validationTests.nonNegativeNum(property)); }, + webSocket: (property, value) => { + describe(property, () => validationTests.configObject(property, value)); + }, + webSocketEnable: (property) => { + describe(property, () => validationTests.boolean(property)); + }, + webSocketReconnect: (property) => { + describe(property, () => validationTests.boolean(property)); + }, + webSocketRejectUnauthorized: (property) => { + describe(property, () => validationTests.boolean(property)); + }, + webSocketPingTimeout: (property) => { + describe(property, () => validationTests.nonNegativeNum(property)); + }, + webSocketReconnectInterval: (property) => { + describe(property, () => validationTests.nonNegativeNum(property)); + }, + webSocketReconnectAttempts: (property) => { + describe(property, () => validationTests.nonNegativeNum(property)); + }, + webSocketMessageInterval: (property) => { + describe(property, () => validationTests.nonNegativeNum(property)); + }, + webSocketGatherAllOptions: (property) => { + describe(property, () => validationTests.boolean(property)); + }, + webSocketUrl: (property, correctValue, incorrectValue) => { + describe(property, () => + validationTests.nullableAcceptValues( + property, + correctValue, + incorrectValue + ) + ); + }, + webSocketSecret: (property) => { + describe(property, () => validationTests.string(property, false)); + }, payload: (property, value) => { describe(property, () => validationTests.configObject(property, value)); },