|
1 | | -import { TcpAddress } from './Transports' |
| 1 | +import { TcpAddress, HttpAddress } from './Transports' |
2 | 2 |
|
3 | | -describe('tcpAddress', () => { |
| 3 | +describe('TcpAddress', () => { |
4 | 4 | const defaults = { |
5 | 5 | host: '127.0.0.1', |
6 | 6 | port: 4321 |
7 | 7 | } |
8 | 8 |
|
9 | | - test('parses a string with host and port', () => { |
| 9 | + test('constructor: string with host and port', () => { |
10 | 10 | expect(new TcpAddress('example.com:2010', defaults)).toEqual({ |
11 | 11 | type: 'tcp', |
12 | 12 | host: 'example.com', |
13 | 13 | port: 2010 |
14 | 14 | }) |
15 | 15 | }) |
16 | 16 |
|
17 | | - test('parses a number as the port', () => { |
| 17 | + test('constructor: number as the port', () => { |
18 | 18 | expect(new TcpAddress(2020, defaults)).toEqual({ |
19 | 19 | type: 'tcp', |
20 | 20 | host: '127.0.0.1', |
21 | 21 | port: 2020 |
22 | 22 | }) |
23 | 23 | }) |
24 | 24 |
|
25 | | - test('parses a string with just port', () => { |
| 25 | + test('constructor: string with just port', () => { |
26 | 26 | expect(new TcpAddress('2030', defaults)).toEqual({ |
27 | 27 | type: 'tcp', |
28 | 28 | host: '127.0.0.1', |
29 | 29 | port: 2030 |
30 | 30 | }) |
31 | 31 | }) |
| 32 | + |
| 33 | + test('toString', () => { |
| 34 | + expect(new TcpAddress().toString()).toEqual('tcp://127.0.0.1:2000') |
| 35 | + }) |
| 36 | +}) |
| 37 | + |
| 38 | +describe('HttpAddress', () => { |
| 39 | + test('constructor: string with host and port', () => { |
| 40 | + expect(new HttpAddress()).toEqual({ |
| 41 | + type: 'http', |
| 42 | + host: '127.0.0.1', |
| 43 | + port: 8000, |
| 44 | + path: '', |
| 45 | + jwt: undefined |
| 46 | + }) |
| 47 | + }) |
| 48 | + |
| 49 | + test('toString', () => { |
| 50 | + expect(new HttpAddress().toString()).toEqual('http://127.0.0.1:8000') |
| 51 | + |
| 52 | + expect(new HttpAddress(undefined, '/some/path').toString()).toEqual( |
| 53 | + 'http://127.0.0.1:8000/some/path' |
| 54 | + ) |
| 55 | + }) |
32 | 56 | }) |
0 commit comments