Skip to content

Commit

Permalink
Add types and reduce function context
Browse files Browse the repository at this point in the history
  • Loading branch information
belcherj committed Feb 7, 2020
1 parent 9c14685 commit 28ae726
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ let props = {
noteBucket: client.bucket('note'),
preferencesBucket: client.bucket('preferences'),
tagBucket: client.bucket('tag'),
isDevConfig: isDevConfig(config),
isDevConfig: isDevConfig(config?.development),
onAuthenticate: (username, password) => {
if (!(username && password)) {
return;
Expand Down
7 changes: 3 additions & 4 deletions lib/utils/is-dev-config/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const isDevConfig = config => {
const isDev = Boolean(config.development);
const isDevConfig = (development: boolean = false) => {
const isDev = Boolean(development);
const whichDB = isDev ? 'Development' : 'Production';
const shouldWarn =
process.env.NODE_ENV === 'production' && config.development;
const shouldWarn = process.env.NODE_ENV === 'production' && development;
const consoleMode = shouldWarn ? 'warn' : 'info';
console[consoleMode](`Simperium config: ${whichDB}`); // eslint-disable-line no-console

Expand Down
9 changes: 4 additions & 5 deletions lib/utils/is-dev-config/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ describe('isDevConfig', () => {
global.console = unmockedConsole;
});

it('should return a boolean of whether config is dev or not', () => {
expect(isDevConfig({ development: true })).toBe(true);
expect(isDevConfig({})).toBe(false);
it('should return a boolean of whether it is given a value or not', () => {
expect(isDevConfig(true)).toBe(true);
expect(isDevConfig()).toBe(false);
});

it('should console.warn when NODE_ENV is production and Simperium is not', () => {
global.process.env.NODE_ENV = 'production';
global.console.warn = jest.fn();
const config = { development: true };
isDevConfig(config);
isDevConfig(true);
expect(global.console.warn).toHaveBeenCalled();
});
});

0 comments on commit 28ae726

Please sign in to comment.