Skip to content

Commit

Permalink
Tests for the WebSocket options.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDalek committed Dec 11, 2024
1 parent 728422c commit 9693a67
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/unit/validation/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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);
Expand Down
49 changes: 49 additions & 0 deletions tests/unit/validation/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/validation/envs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
39 changes: 39 additions & 0 deletions tests/unit/validation/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
},
Expand Down

0 comments on commit 9693a67

Please sign in to comment.