|
6 | 6 | convertChangeData, |
7 | 7 | convertColumn, |
8 | 8 | toArray, |
| 9 | + httpEndpointURL, |
9 | 10 | toJson, |
10 | 11 | toTimestampString, |
11 | 12 | } from '../src/lib/transformers' |
@@ -150,3 +151,74 @@ test('toArray with non-array strings', () => { |
150 | 151 | assert.strictEqual(toArray('missing_closing', 'text'), 'missing_closing') |
151 | 152 | assert.strictEqual(toArray('missing_opening}', 'text'), 'missing_opening}') |
152 | 153 | }) |
| 154 | + |
| 155 | +test('httpEndpointURL', () => { |
| 156 | + // Test basic ws to http conversion |
| 157 | + assert.strictEqual( |
| 158 | + httpEndpointURL('ws://example.com/socket/websocket'), |
| 159 | + 'http://example.com/api/broadcast' |
| 160 | + ) |
| 161 | + |
| 162 | + // Test wss to https conversion |
| 163 | + assert.strictEqual( |
| 164 | + httpEndpointURL('wss://example.com/socket/websocket'), |
| 165 | + 'https://example.com/api/broadcast' |
| 166 | + ) |
| 167 | + |
| 168 | + // Test with /socket path |
| 169 | + assert.strictEqual(httpEndpointURL('ws://example.com/socket'), 'http://example.com/api/broadcast') |
| 170 | + |
| 171 | + // Test with /websocket path |
| 172 | + assert.strictEqual( |
| 173 | + httpEndpointURL('ws://example.com/websocket'), |
| 174 | + 'http://example.com/api/broadcast' |
| 175 | + ) |
| 176 | + |
| 177 | + // Test with trailing slash |
| 178 | + assert.strictEqual( |
| 179 | + httpEndpointURL('ws://example.com/socket/websocket/'), |
| 180 | + 'http://example.com/api/broadcast' |
| 181 | + ) |
| 182 | + |
| 183 | + // Test with port number |
| 184 | + assert.strictEqual( |
| 185 | + httpEndpointURL('ws://example.com:8080/socket/websocket'), |
| 186 | + 'http://example.com:8080/api/broadcast' |
| 187 | + ) |
| 188 | + |
| 189 | + // Test with path prefix |
| 190 | + assert.strictEqual( |
| 191 | + httpEndpointURL('ws://example.com/prefix/socket/websocket'), |
| 192 | + 'http://example.com/prefix/api/broadcast' |
| 193 | + ) |
| 194 | + |
| 195 | + // Test with query parameters |
| 196 | + assert.strictEqual( |
| 197 | + httpEndpointURL('ws://example.com/socket/websocket?apikey=test'), |
| 198 | + 'http://example.com/api/broadcast?apikey=test' |
| 199 | + ) |
| 200 | + |
| 201 | + // Test already http protocol (should remain unchanged) |
| 202 | + assert.strictEqual( |
| 203 | + httpEndpointURL('http://example.com/socket/websocket'), |
| 204 | + 'http://example.com/api/broadcast' |
| 205 | + ) |
| 206 | + |
| 207 | + // Test already https protocol (should remain unchanged) |
| 208 | + assert.strictEqual( |
| 209 | + httpEndpointURL('https://example.com/socket/websocket'), |
| 210 | + 'https://example.com/api/broadcast' |
| 211 | + ) |
| 212 | + |
| 213 | + // Test with multiple trailing slashes |
| 214 | + assert.strictEqual( |
| 215 | + httpEndpointURL('ws://example.com/socket/websocket///'), |
| 216 | + 'http://example.com/api/broadcast' |
| 217 | + ) |
| 218 | + |
| 219 | + // Test with no websocket-specific paths |
| 220 | + assert.strictEqual( |
| 221 | + httpEndpointURL('ws://example.com/some/path'), |
| 222 | + 'http://example.com/some/path/api/broadcast' |
| 223 | + ) |
| 224 | +}) |
0 commit comments