-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#13: WARNING: The FTGO_BACKEND_API_URL variable is not set. Defaulting to a blank string #15: Backend server does not run: - sh: babel: not found - changed CORS parameters for the server and the client
- Loading branch information
1 parent
59610f0
commit 44a53d2
Showing
12 changed files
with
155 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.circleci | ||
build | ||
ci-artefacts | ||
node_modules | ||
reports | ||
server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { getEnvVar } from './envGetter'; | ||
import { ensureEnvVariable, ensureEnvVariables } from './index'; | ||
|
||
jest.mock('./envGetter'); | ||
|
||
const ref = { | ||
current: null | ||
}; | ||
|
||
getEnvVar.mockImplementation((...args) => ref.current && ref.current(...args)) | ||
|
||
describe('A set of utilities to check presence of env variables', () => { | ||
|
||
beforeAll(() => { | ||
ref.current = key => ({ | ||
'DEFINED': 'true', | ||
'DEFINED2': '2' | ||
})[ key ]; | ||
}); | ||
|
||
describe('ensureEnvVariable()', () => { | ||
|
||
test('Checks the existence of an env variable and returns its value', () => { | ||
expect(ensureEnvVariable('DEFINED')).toEqual('true'); | ||
expect(ensureEnvVariable('DEFINED2')).toEqual('2'); | ||
}); | ||
|
||
test('Throws if a variable is not defined', () => { | ||
expect(() => ensureEnvVariable('UN-DEFINED')).toThrow(); | ||
}); | ||
|
||
test('Returns the supplied default value (even falsey) if a variable is not defined', () => { | ||
expect(ensureEnvVariable('UN-DEFINED-2', 2)).toEqual(2); | ||
expect(ensureEnvVariable('UN-DEFINED-0', 0)).toEqual(0); | ||
expect(ensureEnvVariable('UN-DEFINED-false', false)).toEqual(false); | ||
expect(ensureEnvVariable('UN-DEFINED-empty', '')).toEqual(''); | ||
}); | ||
|
||
}); | ||
|
||
describe('ensureEnvVariables()', () => { | ||
|
||
test('Can check several env variables at once, returning an array of their values', () => { | ||
expect(ensureEnvVariables([ 'DEFINED', 'DEFINED2' ])).toEqual([ 'true', '2' ]); | ||
}); | ||
|
||
test('Throws if any of the requested variables are not defined, error message contains missing variable names', () => { | ||
expect(() => ensureEnvVariables([ 'UN-DEFINED', 'UN-DEFINED2', 'DEFINED' ])).toThrow(/(UN-DEFINED.+UN-DEFINED2)|(UN-DEFINED2.+UN-DEFINED)/); | ||
}); | ||
|
||
test('Returns the supplied default value for the corresponding index', () => { | ||
expect(ensureEnvVariables( | ||
[ 'DEFINED', 'UN-DEFINED-2', 'UN-DEFINED-0', 'UN-DEFINED-false', 'UN-DEFINED-empty' | ||
], | ||
[ undefined, 2, 0, false, '' ] | ||
)).toEqual([ 'true', 2, 0, false, '' ]); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
export const getEnvVar = envVar => process.env[ envVar ]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { getEnvVar } from './envGetter'; | ||
|
||
/** | ||
* @description this will be replaced by ensureEnvVariablesWithParameterStore() | ||
* @param envVars | ||
* @param fallbackValues | ||
* @returns {String[]} | ||
*/ | ||
export function ensureEnvVariables(envVars, fallbackValues) { | ||
const hitsAndMisses = Array.from(envVars).map((envVar, idx) => ({ | ||
env: envVar, | ||
val: getEnvVar(envVar), | ||
fallback: fallbackValues && fallbackValues[ idx ] | ||
})); | ||
|
||
const misses = hitsAndMisses.filter(({ val, fallback }) => !val && (typeof fallback === 'undefined')).map(({ env }) => env); | ||
|
||
if (misses.length) { | ||
throw new Error(`Set up these environment variables: ${ misses.join(', ') }`); | ||
} | ||
|
||
return hitsAndMisses.map(({ val, fallback }) => (val || fallback)); | ||
} | ||
|
||
|
||
export function ensureEnvVariable(envVar, fallback) { | ||
const [ result ] = ensureEnvVariables([ envVar ], [ fallback ]); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters