-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathconfig.test.ts
62 lines (61 loc) · 2.62 KB
/
config.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
describe('test suite for configuration', () => {
const net = require('net')
beforeEach(() => {
jest.resetModules()
})
it('test invalid server port', async () => {
process.env.SERVER_PORT = 'string'
const { default: config } = jest.requireActual('../src/config')
expect(config.server.port).toBe(2048)
})
it('test valid server port', async () => {
process.env.SERVER_PORT = '3000'
const { default: config } = jest.requireActual('../src/config')
expect(config.server.port).toBe(3000)
})
it('test missing server port', async () => {
process.env.SERVER_PORT = undefined
const { default: config } = jest.requireActual('../src/config')
expect(config.server.port).toBe(2048)
})
it('test invalid websocket port', async () => {
process.env.WEBSOCKET_PORT = 'invalid'
const { default: config } = jest.requireActual('../src/config')
expect(config.server.websocketPort).toBe(80)
})
it('test valid websocket port', async () => {
process.env.WEBSOCKET_PORT = '3001'
const { default: config } = jest.requireActual('../src/config')
expect(config.server.websocketPort).toBe(3001)
})
it('test missing websocket port', async () => {
process.env.WEBSOCKET_PORT = undefined
const { default: config } = jest.requireActual('../src/config')
expect(config.server.websocketPort).toBe(80)
})
it('test so ssl enabled is set to false', () => {
process.env.SSL_ENABLED = 'foo'
const { default: config } = jest.requireActual('../src/config')
expect(config.ssl.enabled).toBe(false)
})
it('test so ssl can be enabled', () => {
process.env.SSL_ENABLED = '1'
const { default: config } = jest.requireActual('../src/config')
expect(config.ssl.enabled).toBe(true)
})
it('test so server address is ip', () => {
process.env.SERVER_ADDRESS = '127.0.0.1'
const { default: config } = jest.requireActual('../src/config')
expect(net.isIPv4(config.server.address)).toBe(true)
})
it ('test so multiple origins is trimmed', async () => {
process.env.ALLOWED_ORIGINS = 'localhost,, 127.0.0.1,, ,'
const { default: config }= jest.requireActual('../src/config')
expect(config.allowedOrigins).toHaveLength(2)
})
it ('test so duplicate origins is removed', async () => {
process.env.ALLOWED_ORIGINS = 'localhost,127.0.0.1,localhost,192.168.33.10'
const { default: config }= jest.requireActual('../src/config')
expect(config.allowedOrigins).toHaveLength(3)
})
})