From d5fc0f7a35955f7ce4da5d95b7faeb6cddf40b78 Mon Sep 17 00:00:00 2001 From: JoaoLeal12 Date: Tue, 21 Jun 2022 11:42:00 +0100 Subject: [PATCH 1/8] feat: add getRipeConfigPublicOptions --- js/env.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/env.js b/js/env.js index 1d08a2c..41a9d79 100644 --- a/js/env.js +++ b/js/env.js @@ -118,3 +118,9 @@ export const getRipeWhiteAdminOptions = (environment, fallback = {}) => { return fallback; } }; + +export const getRipeConfigPublicOptions = (url = null) => { + return { + url: url || "https://config-public.platforme.com/" + }; +}; From c8ec4140de075f03207e8995b54583cc9b0a6311 Mon Sep 17 00:00:00 2001 From: JoaoLeal12 Date: Tue, 21 Jun 2022 11:42:31 +0100 Subject: [PATCH 2/8] feat: add getRipeConfigOptions --- js/env.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/env.js b/js/env.js index 41a9d79..1bdab4f 100644 --- a/js/env.js +++ b/js/env.js @@ -124,3 +124,9 @@ export const getRipeConfigPublicOptions = (url = null) => { url: url || "https://config-public.platforme.com/" }; }; + +export const getRipeConfigOptions = (url = null) => { + return { + url: url || "https://config.platforme.com/" + }; +}; From e3a8143df464b5bd37e8a0294973ea9d3cd149a6 Mon Sep 17 00:00:00 2001 From: JoaoLeal12 Date: Tue, 21 Jun 2022 11:44:24 +0100 Subject: [PATCH 3/8] docs: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ed6735..796f966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Add `getRipeWhiteOptions` method - [ripe-util-vue/#267](https://github.com/ripe-tech/ripe-util-vue/issues/267) * Add testing to env methods * Add option to reverse the `dateString` - [ripe-util-vue/#259](https://github.com/ripe-tech/ripe-util-vue/issues/259) +* Add `getRipeConfigPublicOptions` and `getRipeConfigOptions` method - [ripe-white/#961](https://github.com/ripe-tech/ripe-white/issues/961) ### Changed From f3dc659959b0782434703745ff8f02809ff74b44 Mon Sep 17 00:00:00 2001 From: JoaoLeal12 Date: Tue, 21 Jun 2022 14:17:53 +0100 Subject: [PATCH 4/8] refactor: reorder methods --- js/env.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/env.js b/js/env.js index 1bdab4f..b0a585c 100644 --- a/js/env.js +++ b/js/env.js @@ -119,14 +119,14 @@ export const getRipeWhiteAdminOptions = (environment, fallback = {}) => { } }; -export const getRipeConfigPublicOptions = (url = null) => { +export const getRipeConfigOptions = (url = null) => { return { - url: url || "https://config-public.platforme.com/" + url: url || "https://config.platforme.com/" }; }; -export const getRipeConfigOptions = (url = null) => { +export const getRipeConfigPublicOptions = (url = null) => { return { - url: url || "https://config.platforme.com/" + url: url || "https://config-public.platforme.com/" }; }; From 065aea86ba6c2b3614a91166facc31ba543537d6 Mon Sep 17 00:00:00 2001 From: JoaoLeal12 Date: Tue, 21 Jun 2022 16:12:25 +0100 Subject: [PATCH 5/8] refactor: change parameters --- js/env.js | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/js/env.js b/js/env.js index b0a585c..f6396c3 100644 --- a/js/env.js +++ b/js/env.js @@ -119,14 +119,42 @@ export const getRipeWhiteAdminOptions = (environment, fallback = {}) => { } }; -export const getRipeConfigOptions = (url = null) => { - return { - url: url || "https://config.platforme.com/" - }; +export const getRipeConfigOptions = (environment, fallback = {}) => { + switch (environment) { + case "ci": + case "test": + case "now": + case "now-branch": + case "sandbox": + case "stage": + return { + baseUrl: "https://master--ripe-config.netlify.app" + }; + case "production": + return { + baseUrl: "https://config.platforme.com/" + }; + default: + return fallback; + } }; -export const getRipeConfigPublicOptions = (url = null) => { - return { - url: url || "https://config-public.platforme.com/" - }; +export const getRipeConfigPublicOptions = (environment, fallback = {}) => { + switch (environment) { + case "ci": + case "test": + case "now": + case "now-branch": + case "sandbox": + case "stage": + return { + baseUrl: "https://master--ripe-config-public.netlify.app" + }; + case "production": + return { + baseUrl: "https://config-public.platforme.com/" + }; + default: + return fallback; + } }; From 5d5069c9d54ba0e17f3c5f51baab5788db8022ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Leal?= Date: Wed, 22 Jun 2022 09:51:52 +0100 Subject: [PATCH 6/8] test: add tests --- js/env.js | 4 ++-- test/env.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/js/env.js b/js/env.js index f6396c3..139e26b 100644 --- a/js/env.js +++ b/js/env.js @@ -128,7 +128,7 @@ export const getRipeConfigOptions = (environment, fallback = {}) => { case "sandbox": case "stage": return { - baseUrl: "https://master--ripe-config.netlify.app" + baseUrl: "https://master--ripe-config.netlify.app/" }; case "production": return { @@ -148,7 +148,7 @@ export const getRipeConfigPublicOptions = (environment, fallback = {}) => { case "sandbox": case "stage": return { - baseUrl: "https://master--ripe-config-public.netlify.app" + baseUrl: "https://master--ripe-config-public.netlify.app/" }; case "production": return { diff --git a/test/env.js b/test/env.js index 7e33dbd..91f8e45 100644 --- a/test/env.js +++ b/test/env.js @@ -248,3 +248,67 @@ describe("Env", function() { }); }); }); + +describe("#getRipeConfigOptions()", function() { + it("should return ci option for 'ci', 'test', 'now', 'sandbox', and 'stage' environments", function() { + const ciEnvOptions = ripeCommons.getRipeConfigOptions("ci"); + const testEnvOptions = ripeCommons.getRipeConfigOptions("test"); + const nowEnvOptions = ripeCommons.getRipeConfigOptions("now"); + const sandboxEnvOptions = ripeCommons.getRipeConfigOptions("sandbox"); + const stageEnvOptions = ripeCommons.getRipeConfigOptions("stage"); + assert.deepStrictEqual(ciEnvOptions, { + url: "https://master--ripe-config.netlify.app/" + }); + assert.deepStrictEqual(testEnvOptions, { + url: "https://master--ripe-config.netlify.app/" + }); + assert.deepStrictEqual(nowEnvOptions, { + url: "https://master--ripe-config.netlify.app/" + }); + assert.deepStrictEqual(sandboxEnvOptions, { + url: "https://master--ripe-config.netlify.app/" + }); + assert.deepStrictEqual(stageEnvOptions, { + url: "https://master--ripe-config.netlify.app/" + }); + }); + + it("should return production option for 'production' environment", function() { + const productionEnvOptions = ripeCommons.getRipeConfigOptions("production"); + assert.deepStrictEqual(productionEnvOptions, { + url: "https://config.platforme.com/" + }); + }); +}); + +describe("#getRipeConfigPublicOptions()", function() { + it("should return production option for 'ci', 'test', 'now', 'sandbox', and 'stage' environments", function() { + const ciEnvOptions = ripeCommons.getRipeConfigPublicOptions("ci"); + const testEnvOptions = ripeCommons.getRipeConfigPublicOptions("test"); + const nowEnvOptions = ripeCommons.getRipeConfigPublicOptions("now"); + const sandboxEnvOptions = ripeCommons.getRipeConfigPublicOptions("sandbox"); + const stageEnvOptions = ripeCommons.getRipeConfigPublicOptions("stage"); + assert.deepStrictEqual(ciEnvOptions, { + url: "https://master--ripe-config-public.netlify.app/" + }); + assert.deepStrictEqual(testEnvOptions, { + url: "https://master--ripe-config-public.netlify.app/" + }); + assert.deepStrictEqual(nowEnvOptions, { + url: "https://master--ripe-config-public.netlify.app/" + }); + assert.deepStrictEqual(sandboxEnvOptions, { + url: "https://master--ripe-config-public.netlify.app/" + }); + assert.deepStrictEqual(stageEnvOptions, { + url: "https://master--ripe-config-public.netlify.app/" + }); + }); + + it("should return production option for 'production' environment", function() { + const productionEnvOptions = ripeCommons.getRipeConfigPublicOptions("production"); + assert.deepStrictEqual(productionEnvOptions, { + url: "https://config-public.platforme.com/" + }); + }); +}); From d639b25ed15b83d604e9bc7711ee1bf311286761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Leal?= Date: Wed, 22 Jun 2022 09:54:27 +0100 Subject: [PATCH 7/8] refactor: rename options param --- js/env.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/env.js b/js/env.js index 139e26b..cb2399c 100644 --- a/js/env.js +++ b/js/env.js @@ -128,11 +128,11 @@ export const getRipeConfigOptions = (environment, fallback = {}) => { case "sandbox": case "stage": return { - baseUrl: "https://master--ripe-config.netlify.app/" + url: "https://master--ripe-config.netlify.app/" }; case "production": return { - baseUrl: "https://config.platforme.com/" + url: "https://config.platforme.com/" }; default: return fallback; @@ -148,11 +148,11 @@ export const getRipeConfigPublicOptions = (environment, fallback = {}) => { case "sandbox": case "stage": return { - baseUrl: "https://master--ripe-config-public.netlify.app/" + url: "https://master--ripe-config-public.netlify.app/" }; case "production": return { - baseUrl: "https://config-public.platforme.com/" + url: "https://config-public.platforme.com/" }; default: return fallback; From 42ab9a8479bd3161ba72ab423f8c967b161484ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Leal?= Date: Wed, 22 Jun 2022 10:20:14 +0100 Subject: [PATCH 8/8] test: add fallback tests --- test/env.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/env.js b/test/env.js index 91f8e45..0467c1f 100644 --- a/test/env.js +++ b/test/env.js @@ -279,6 +279,20 @@ describe("#getRipeConfigOptions()", function() { url: "https://config.platforme.com/" }); }); + + it("should return fallback options when environment isn't part of the available options", function() { + const uatEnvOptions = ripeCommons.getRipeCoreOptions("uat"); + assert.deepStrictEqual(uatEnvOptions, {}); + }); + + it("should return the given fallback options when environment isn't part of the available options", function() { + const fallbackEnvOptions = ripeCommons.getRipeCoreOptions("uat", { + url: "https://config.platforme.com/" + }); + assert.deepStrictEqual(fallbackEnvOptions, { + url: "https://config.platforme.com/" + }); + }); }); describe("#getRipeConfigPublicOptions()", function() { @@ -311,4 +325,18 @@ describe("#getRipeConfigPublicOptions()", function() { url: "https://config-public.platforme.com/" }); }); + + it("should return fallback options when environment isn't part of the available options", function() { + const uatEnvOptions = ripeCommons.getRipeCoreOptions("uat"); + assert.deepStrictEqual(uatEnvOptions, {}); + }); + + it("should return the given fallback options when environment isn't part of the available options", function() { + const fallbackEnvOptions = ripeCommons.getRipeCoreOptions("uat", { + url: "https://config-public.platforme.com/" + }); + assert.deepStrictEqual(fallbackEnvOptions, { + url: "https://config-public.platforme.com/" + }); + }); });