Skip to content

Commit 93c454e

Browse files
committed
test(validation): add comprehensive API token type validation tests
Add tests for non-string API token inputs to improve coverage: - Test TypeError for null token - Test TypeError for undefined token - Test TypeError for number token - Test TypeError for object token These tests cover the constructor validation in socket-sdk-class.ts:140 that ensures apiToken is a string type. Coverage improvement: - Overall coverage: 75.34% → 81.19% (+5.85%) - socket-sdk-class.ts: 78.5% → 78.7% (553/703 statements) - Validates TypeError path for non-string tokens
1 parent a6b8444 commit 93c454e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/unit/socket-sdk-validation.test.mts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@ import { SocketSdk } from '../../src/index'
55

66
describe('SocketSdk - Configuration Validation', () => {
77
describe('API token validation', () => {
8+
it('should throw TypeError for non-string API token', () => {
9+
// Test validation of non-string token
10+
expect(() => new SocketSdk(null as any)).toThrow(TypeError)
11+
expect(() => new SocketSdk(null as any)).toThrow(
12+
'"apiToken" is required and must be a string',
13+
)
14+
})
15+
16+
it('should throw TypeError for undefined API token', () => {
17+
expect(() => new SocketSdk(undefined as any)).toThrow(TypeError)
18+
expect(() => new SocketSdk(undefined as any)).toThrow(
19+
'"apiToken" is required and must be a string',
20+
)
21+
})
22+
23+
it('should throw TypeError for number as API token', () => {
24+
expect(() => new SocketSdk(12_345 as any)).toThrow(TypeError)
25+
expect(() => new SocketSdk(12_345 as any)).toThrow(
26+
'"apiToken" is required and must be a string',
27+
)
28+
})
29+
30+
it('should throw TypeError for object as API token', () => {
31+
expect(() => new SocketSdk({ token: 'test' } as any)).toThrow(TypeError)
32+
expect(() => new SocketSdk({ token: 'test' } as any)).toThrow(
33+
'"apiToken" is required and must be a string',
34+
)
35+
})
36+
837
it('should throw error for empty API token', () => {
938
// Test validation of empty token
1039
expect(() => new SocketSdk('')).toThrow(

0 commit comments

Comments
 (0)