1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00
unleash.unleash/src/lib/util/parseEnvVar.test.ts
olav 42d64c8803
feat: add CORS instance settings (#1957)
* feat: add CORS instance settings

* refactor: disallow arbitrary asterisks in CORS origins
2022-08-26 09:09:48 +02:00

42 lines
1.7 KiB
TypeScript

import {
parseEnvVarBoolean,
parseEnvVarNumber,
parseEnvVarStrings,
} from './parseEnvVar';
test('parseEnvVarNumber', () => {
expect(parseEnvVarNumber('', 1)).toEqual(1);
expect(parseEnvVarNumber('', 2)).toEqual(2);
expect(parseEnvVarNumber(' ', 1)).toEqual(1);
expect(parseEnvVarNumber('a', 1)).toEqual(1);
expect(parseEnvVarNumber('1', 1)).toEqual(1);
expect(parseEnvVarNumber('2', 1)).toEqual(2);
expect(parseEnvVarNumber('2e2', 1)).toEqual(2);
expect(parseEnvVarNumber('-1', 1)).toEqual(-1);
});
test('parseEnvVarBoolean', () => {
expect(parseEnvVarBoolean('', true)).toEqual(true);
expect(parseEnvVarBoolean('', false)).toEqual(false);
expect(parseEnvVarBoolean(' ', false)).toEqual(false);
expect(parseEnvVarBoolean('1', false)).toEqual(true);
expect(parseEnvVarBoolean('2', false)).toEqual(false);
expect(parseEnvVarBoolean('t', false)).toEqual(true);
expect(parseEnvVarBoolean('f', false)).toEqual(false);
expect(parseEnvVarBoolean('true', false)).toEqual(true);
expect(parseEnvVarBoolean('false', false)).toEqual(false);
expect(parseEnvVarBoolean('test', false)).toEqual(false);
});
test('parseEnvVarStringList', () => {
expect(parseEnvVarStrings(undefined, [])).toEqual([]);
expect(parseEnvVarStrings(undefined, ['a'])).toEqual(['a']);
expect(parseEnvVarStrings('', ['a'])).toEqual([]);
expect(parseEnvVarStrings('', [])).toEqual([]);
expect(parseEnvVarStrings(' ', [])).toEqual([]);
expect(parseEnvVarStrings('a', ['*'])).toEqual(['a']);
expect(parseEnvVarStrings('a,b,c', [])).toEqual(['a', 'b', 'c']);
expect(parseEnvVarStrings('a,b,c', [])).toEqual(['a', 'b', 'c']);
expect(parseEnvVarStrings(' a,,,b, c , ,', [])).toEqual(['a', 'b', 'c']);
});