2020-08-13 23:27:00 +02:00
|
|
|
import _ from 'lodash';
|
2020-11-15 11:14:09 +01:00
|
|
|
import {
|
|
|
|
DEFAULT_DOMAIN,
|
|
|
|
DEFAULT_PORT,
|
|
|
|
DEFAULT_PROTOCOL,
|
|
|
|
getListListenAddresses,
|
|
|
|
} from '../src/cli-utils';
|
2020-03-08 09:19:12 +01:00
|
|
|
|
|
|
|
describe('getListListenAddresses test', () => {
|
2020-08-13 23:27:00 +02:00
|
|
|
test('should return no address if a single address is wrong', () => {
|
|
|
|
// @ts-ignore
|
|
|
|
const addrs = getListListenAddresses('wrong');
|
2020-03-08 09:19:12 +01:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
expect(_.isArray(addrs)).toBeTruthy();
|
|
|
|
expect(addrs).toHaveLength(0);
|
|
|
|
});
|
2020-03-08 09:19:12 +01:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
test('should return no address if a two address are wrong', () => {
|
|
|
|
// @ts-ignore
|
|
|
|
const addrs = getListListenAddresses(['wrong', 'same-wrong']);
|
2020-03-08 09:19:12 +01:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
expect(_.isArray(addrs)).toBeTruthy();
|
|
|
|
expect(addrs).toHaveLength(0);
|
|
|
|
});
|
2020-03-08 09:19:12 +01:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
test('should return a list of 1 address provided', () => {
|
|
|
|
// @ts-ignore
|
|
|
|
const addrs = getListListenAddresses(null, '1000');
|
2020-03-08 09:19:12 +01:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
expect(_.isArray(addrs)).toBeTruthy();
|
|
|
|
expect(addrs).toHaveLength(1);
|
|
|
|
});
|
2020-03-08 09:19:12 +01:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
test('should return a list of 2 address provided', () => {
|
|
|
|
// @ts-ignore
|
|
|
|
const addrs = getListListenAddresses(null, ['1000', '2000']);
|
2020-03-08 09:19:12 +01:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
expect(_.isArray(addrs)).toBeTruthy();
|
|
|
|
expect(addrs).toHaveLength(2);
|
|
|
|
});
|
2020-03-08 09:19:12 +01:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
test(`should return by default ${DEFAULT_PORT}`, () => {
|
|
|
|
// @ts-ignore
|
|
|
|
const [addrs] = getListListenAddresses();
|
2020-03-08 09:19:12 +01:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
// @ts-ignore
|
|
|
|
expect(addrs.proto).toBe(DEFAULT_PROTOCOL);
|
|
|
|
// @ts-ignore
|
|
|
|
expect(addrs.host).toBe(DEFAULT_DOMAIN);
|
|
|
|
// @ts-ignore
|
|
|
|
expect(addrs.port).toBe(DEFAULT_PORT);
|
|
|
|
});
|
2020-03-08 09:19:12 +01:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
test('should return default proto, host and custom port', () => {
|
|
|
|
const initPort = '1000';
|
|
|
|
// @ts-ignore
|
|
|
|
const [addrs] = getListListenAddresses(null, initPort);
|
2020-03-08 09:19:12 +01:00
|
|
|
|
2020-08-13 23:27:00 +02:00
|
|
|
// @ts-ignore
|
|
|
|
expect(addrs.proto).toEqual(DEFAULT_PROTOCOL);
|
|
|
|
// @ts-ignore
|
|
|
|
expect(addrs.host).toEqual(DEFAULT_DOMAIN);
|
|
|
|
// @ts-ignore
|
|
|
|
expect(addrs.port).toEqual(initPort);
|
|
|
|
});
|
2020-03-08 09:19:12 +01:00
|
|
|
});
|