diff --git a/src/constants-test.js b/src/constants-test.js index a8d649c3..36fea6a1 100644 --- a/src/constants-test.js +++ b/src/constants-test.js @@ -5,6 +5,7 @@ describe("constants", () => { //setup beforeEach(() => { process.env.NODE_ENV = "development"; + process.env.MONDAY_DOMAIN = undefined; process.env.MONDAY_COM_PROTOCOL = undefined; process.env.MONDAY_COM_DOMAIN = undefined; process.env.MONDAY_SUBDOMAIN_API = undefined; @@ -35,44 +36,79 @@ describe("constants", () => { expect(constants.MONDAY_OAUTH_TOKEN_URL).to.eq(MONDAY_OAUTH_TOKEN_URL); }); - it("constants should be correct", () => { - const keys = Object.keys(constants); - let key; - let value; - for (let i = 0; i < keys.length; i++) { - key = keys[i]; - value = constants[key]; - - switch (key) { - case "MONDAY_DOMAIN": { - expect(value).to.eq("monday.com"); - break; - } - - case "MONDAY_PROTOCOL": { - expect(value).to.eq("https"); - break; - } - - case "MONDAY_API_URL": { - expect(value).to.eq("https://api.monday.com/v2"); - break; - } - - case "MONDAY_OAUTH_URL": { - expect(value).to.eq("https://auth.monday.com/oauth2/authorize"); - break; - } - - case "MONDAY_OAUTH_TOKEN_URL": { - expect(value).to.eq("https://auth.monday.com/oauth2/token"); - break; - } - - default: { - throw new Error(`missing test for this constant: ${key}`); - } - } - } + describe("check that constants are correct when NODE_ENV is development", () => { + it("MONDAY_DOMAIN should be correct", () => { + expect(constants.MONDAY_DOMAIN).to.eq("monday.com"); + }); + + it("MONDAY_PROTOCOL should be correct", () => { + expect(constants.MONDAY_PROTOCOL).to.eq("https"); + }); + + it("MONDAY_API_URL should be correct", () => { + expect(constants.MONDAY_API_URL).to.eq("https://api.monday.com/v2"); + }); + + it("MONDAY_OAUTH_URL should be correct", () => { + expect(constants.MONDAY_OAUTH_URL).to.eq("https://auth.monday.com/oauth2/authorize"); + }); + + it("MONDAY_OAUTH_TOKEN_URL should be correct", () => { + expect(constants.MONDAY_OAUTH_TOKEN_URL).to.eq("https://auth.monday.com/oauth2/token"); + }); + }); + + describe("check that constants are correct when NODE_ENV is undefined", () => { + beforeEach(() => { + process.env.NODE_ENV = undefined; + process.env.MONDAY_COM_DOMAIN = "should not be used"; + }); + + it("MONDAY_DOMAIN should be correct", () => { + expect(constants.MONDAY_DOMAIN).to.eq("monday.com"); + }); + + it("MONDAY_PROTOCOL should be correct", () => { + expect(constants.MONDAY_PROTOCOL).to.eq("https"); + }); + + it("MONDAY_API_URL should be correct", () => { + expect(constants.MONDAY_API_URL).to.eq("https://api.monday.com/v2"); + }); + + it("MONDAY_OAUTH_URL should be correct", () => { + expect(constants.MONDAY_OAUTH_URL).to.eq("https://auth.monday.com/oauth2/authorize"); + }); + + it("MONDAY_OAUTH_TOKEN_URL should be correct", () => { + expect(constants.MONDAY_OAUTH_TOKEN_URL).to.eq("https://auth.monday.com/oauth2/token"); + }); + }); + + describe("check that constants are correct when NODE_ENV is undefined", () => { + beforeEach(() => { + process.env.NODE_ENV = "production"; + process.env.MONDAY_COM_DOMAIN = "should not be used"; + }); + + it("MONDAY_DOMAIN should be correct", () => { + expect(constants.MONDAY_DOMAIN).to.eq("monday.com"); + }); + + it("MONDAY_PROTOCOL should be correct", () => { + expect(constants.MONDAY_PROTOCOL).to.eq("https"); + }); + + it("MONDAY_API_URL should be correct", () => { + expect(constants.MONDAY_API_URL).to.eq("https://api.monday.com/v2"); + }); + + it("MONDAY_OAUTH_URL should be correct", () => { + expect(constants.MONDAY_OAUTH_URL).to.eq("https://auth.monday.com/oauth2/authorize"); + }); + + it("MONDAY_OAUTH_TOKEN_URL should be correct", () => { + expect(constants.MONDAY_OAUTH_TOKEN_URL).to.eq("https://auth.monday.com/oauth2/token"); + }); }); }); diff --git a/src/constants.js b/src/constants.js index 8478fc7c..de08088d 100644 --- a/src/constants.js +++ b/src/constants.js @@ -7,7 +7,9 @@ function isNodeDevStageEnv() { } const getEnvOrDefault = (key, defaultVal) => { - return isNodeDevStageEnv() && process.env[key] !== "undefined" ? process.env[key] : defaultVal; + return isNodeDevStageEnv() && process.env[key] !== "undefined" && process.env[key] !== undefined + ? process.env[key] + : defaultVal; }; const MONDAY_PROTOCOL = () => getEnvOrDefault("MONDAY_COM_PROTOCOL", "https");