From 3e352bf70030d5958b4b3266e1b83b33742dfa1f Mon Sep 17 00:00:00 2001 From: "Jonathan (JB) Belcher" Date: Fri, 7 Feb 2020 13:39:11 -0500 Subject: [PATCH] Add types and reduce function context --- lib/boot.ts | 2 +- lib/utils/is-dev-config/index.ts | 7 +++---- lib/utils/is-dev-config/test.ts | 9 ++++----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/boot.ts b/lib/boot.ts index c0667da61..6716088c7 100644 --- a/lib/boot.ts +++ b/lib/boot.ts @@ -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; diff --git a/lib/utils/is-dev-config/index.ts b/lib/utils/is-dev-config/index.ts index cbfddcca1..2ee73ed13 100644 --- a/lib/utils/is-dev-config/index.ts +++ b/lib/utils/is-dev-config/index.ts @@ -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 diff --git a/lib/utils/is-dev-config/test.ts b/lib/utils/is-dev-config/test.ts index 02765b7ce..58df98e08 100644 --- a/lib/utils/is-dev-config/test.ts +++ b/lib/utils/is-dev-config/test.ts @@ -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(); }); });