@volley/recognition-client-sdk 0.1.200 → 0.1.210
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -15
- package/dist/{browser-CDQ_TzeH.d.ts → browser-C4ZssGoU.d.ts} +4 -3
- package/dist/index.d.ts +9 -5
- package/dist/index.js +24 -7
- package/dist/index.js.map +1 -1
- package/dist/recog-client-sdk.browser.d.ts +1 -1
- package/dist/recog-client-sdk.browser.js +24 -7
- package/dist/recog-client-sdk.browser.js.map +1 -1
- package/package.json +16 -16
- package/src/config-builder.spec.ts +265 -0
- package/src/factory.spec.ts +215 -0
- package/src/factory.ts +4 -0
- package/src/recognition-client.spec.ts +179 -0
- package/src/recognition-client.ts +44 -1
- package/src/recognition-client.types.ts +2 -2
- package/src/simplified-vgf-recognition-client.spec.ts +6 -0
- package/src/simplified-vgf-recognition-client.ts +3 -3
- package/src/utils/message-handler.spec.ts +311 -0
- package/src/utils/url-builder.spec.ts +203 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for URL Builder
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { buildWebSocketUrl, UrlBuilderConfig } from './url-builder.js';
|
|
6
|
+
import { RecognitionContextTypeV1 } from '@recog/shared-types';
|
|
7
|
+
|
|
8
|
+
// Mock the shared-config module
|
|
9
|
+
jest.mock('@recog/shared-config', () => ({
|
|
10
|
+
getRecognitionServiceBase: jest.fn().mockReturnValue({
|
|
11
|
+
wsBase: 'wss://recognition.volley.com'
|
|
12
|
+
})
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
describe('buildWebSocketUrl', () => {
|
|
16
|
+
const baseConfig: UrlBuilderConfig = {
|
|
17
|
+
audioUtteranceId: 'test-utterance-123'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
it('should build URL with only audioUtteranceId', () => {
|
|
21
|
+
const url = buildWebSocketUrl(baseConfig);
|
|
22
|
+
expect(url).toContain('audioUtteranceId=test-utterance-123');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should use default URL if not provided', () => {
|
|
26
|
+
const url = buildWebSocketUrl(baseConfig);
|
|
27
|
+
expect(url).toContain('wss://recognition.volley.com/ws/v1/recognize');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should use custom URL if provided', () => {
|
|
31
|
+
const config = {
|
|
32
|
+
...baseConfig,
|
|
33
|
+
url: 'ws://localhost:3101/ws/v1/recognize'
|
|
34
|
+
};
|
|
35
|
+
const url = buildWebSocketUrl(config);
|
|
36
|
+
expect(url).toContain('ws://localhost:3101/ws/v1/recognize');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should add userId to query parameters', () => {
|
|
40
|
+
const config = {
|
|
41
|
+
...baseConfig,
|
|
42
|
+
userId: 'user-123'
|
|
43
|
+
};
|
|
44
|
+
const url = buildWebSocketUrl(config);
|
|
45
|
+
expect(url).toContain('userId=user-123');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should add gameSessionId to query parameters', () => {
|
|
49
|
+
const config = {
|
|
50
|
+
...baseConfig,
|
|
51
|
+
gameSessionId: 'session-456'
|
|
52
|
+
};
|
|
53
|
+
const url = buildWebSocketUrl(config);
|
|
54
|
+
expect(url).toContain('gameSessionId=session-456');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should add deviceId to query parameters', () => {
|
|
58
|
+
const config = {
|
|
59
|
+
...baseConfig,
|
|
60
|
+
deviceId: 'device-789'
|
|
61
|
+
};
|
|
62
|
+
const url = buildWebSocketUrl(config);
|
|
63
|
+
expect(url).toContain('deviceId=device-789');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should add accountId to query parameters', () => {
|
|
67
|
+
const config = {
|
|
68
|
+
...baseConfig,
|
|
69
|
+
accountId: 'account-abc'
|
|
70
|
+
};
|
|
71
|
+
const url = buildWebSocketUrl(config);
|
|
72
|
+
expect(url).toContain('accountId=account-abc');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should add questionAnswerId to query parameters', () => {
|
|
76
|
+
const config = {
|
|
77
|
+
...baseConfig,
|
|
78
|
+
questionAnswerId: 'qa-xyz'
|
|
79
|
+
};
|
|
80
|
+
const url = buildWebSocketUrl(config);
|
|
81
|
+
expect(url).toContain('questionAnswerId=qa-xyz');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should add platform to query parameters', () => {
|
|
85
|
+
const config = {
|
|
86
|
+
...baseConfig,
|
|
87
|
+
platform: 'ios'
|
|
88
|
+
};
|
|
89
|
+
const url = buildWebSocketUrl(config);
|
|
90
|
+
expect(url).toContain('platform=ios');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should add gameId and gamePhase from gameContext', () => {
|
|
94
|
+
const config = {
|
|
95
|
+
...baseConfig,
|
|
96
|
+
gameContext: {
|
|
97
|
+
type: RecognitionContextTypeV1.GAME_CONTEXT as const,
|
|
98
|
+
gameId: 'test-game',
|
|
99
|
+
gamePhase: 'test-phase'
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const url = buildWebSocketUrl(config);
|
|
103
|
+
expect(url).toContain('gameId=test-game');
|
|
104
|
+
expect(url).toContain('gamePhase=test-phase');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should serialize callbackUrls as JSON', () => {
|
|
108
|
+
const callbackUrls = [
|
|
109
|
+
{ url: 'https://example.com/callback', messageTypes: ['transcript'] },
|
|
110
|
+
{ url: 'https://example.com/metadata', messageTypes: ['metadata'] }
|
|
111
|
+
];
|
|
112
|
+
const config = {
|
|
113
|
+
...baseConfig,
|
|
114
|
+
callbackUrls
|
|
115
|
+
};
|
|
116
|
+
const url = buildWebSocketUrl(config);
|
|
117
|
+
expect(url).toContain('callbackUrls=');
|
|
118
|
+
// Decode and verify JSON structure
|
|
119
|
+
const urlObj = new URL(url);
|
|
120
|
+
const callbackUrlsParam = urlObj.searchParams.get('callbackUrls');
|
|
121
|
+
expect(callbackUrlsParam).toBeDefined();
|
|
122
|
+
expect(JSON.parse(callbackUrlsParam!)).toEqual(callbackUrls);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should not add callbackUrls if empty array', () => {
|
|
126
|
+
const config = {
|
|
127
|
+
...baseConfig,
|
|
128
|
+
callbackUrls: []
|
|
129
|
+
};
|
|
130
|
+
const url = buildWebSocketUrl(config);
|
|
131
|
+
expect(url).not.toContain('callbackUrls=');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('should not add optional parameters if not provided', () => {
|
|
135
|
+
const url = buildWebSocketUrl(baseConfig);
|
|
136
|
+
expect(url).not.toContain('userId=');
|
|
137
|
+
expect(url).not.toContain('gameSessionId=');
|
|
138
|
+
expect(url).not.toContain('deviceId=');
|
|
139
|
+
expect(url).not.toContain('accountId=');
|
|
140
|
+
expect(url).not.toContain('questionAnswerId=');
|
|
141
|
+
expect(url).not.toContain('platform=');
|
|
142
|
+
expect(url).not.toContain('gameId=');
|
|
143
|
+
expect(url).not.toContain('gamePhase=');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should handle all parameters together', () => {
|
|
147
|
+
const config: UrlBuilderConfig = {
|
|
148
|
+
url: 'ws://localhost:3101/ws/v1/recognize',
|
|
149
|
+
audioUtteranceId: 'test-utterance-123',
|
|
150
|
+
userId: 'user-123',
|
|
151
|
+
gameSessionId: 'session-456',
|
|
152
|
+
deviceId: 'device-789',
|
|
153
|
+
accountId: 'account-abc',
|
|
154
|
+
questionAnswerId: 'qa-xyz',
|
|
155
|
+
platform: 'ios',
|
|
156
|
+
gameContext: {
|
|
157
|
+
type: RecognitionContextTypeV1.GAME_CONTEXT as const,
|
|
158
|
+
gameId: 'test-game',
|
|
159
|
+
gamePhase: 'test-phase'
|
|
160
|
+
},
|
|
161
|
+
callbackUrls: [
|
|
162
|
+
{ url: 'https://example.com/callback', messageTypes: ['transcript'] }
|
|
163
|
+
]
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const url = buildWebSocketUrl(config);
|
|
167
|
+
expect(url).toContain('ws://localhost:3101/ws/v1/recognize');
|
|
168
|
+
expect(url).toContain('audioUtteranceId=test-utterance-123');
|
|
169
|
+
expect(url).toContain('userId=user-123');
|
|
170
|
+
expect(url).toContain('gameSessionId=session-456');
|
|
171
|
+
expect(url).toContain('deviceId=device-789');
|
|
172
|
+
expect(url).toContain('accountId=account-abc');
|
|
173
|
+
expect(url).toContain('questionAnswerId=qa-xyz');
|
|
174
|
+
expect(url).toContain('platform=ios');
|
|
175
|
+
expect(url).toContain('gameId=test-game');
|
|
176
|
+
expect(url).toContain('gamePhase=test-phase');
|
|
177
|
+
expect(url).toContain('callbackUrls=');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('should properly encode special characters in parameters', () => {
|
|
181
|
+
const config = {
|
|
182
|
+
...baseConfig,
|
|
183
|
+
userId: 'user@example.com',
|
|
184
|
+
platform: 'iOS 17.0'
|
|
185
|
+
};
|
|
186
|
+
const url = buildWebSocketUrl(config);
|
|
187
|
+
// URL should be properly encoded
|
|
188
|
+
expect(url).toBeDefined();
|
|
189
|
+
const urlObj = new URL(url);
|
|
190
|
+
expect(urlObj.searchParams.get('userId')).toBe('user@example.com');
|
|
191
|
+
expect(urlObj.searchParams.get('platform')).toBe('iOS 17.0');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should create valid URL object', () => {
|
|
195
|
+
const config = {
|
|
196
|
+
...baseConfig,
|
|
197
|
+
userId: 'user-123'
|
|
198
|
+
};
|
|
199
|
+
const url = buildWebSocketUrl(config);
|
|
200
|
+
// Should not throw
|
|
201
|
+
expect(() => new URL(url)).not.toThrow();
|
|
202
|
+
});
|
|
203
|
+
});
|