Skip to content

Commit

Permalink
Merge pull request #46 from ripe-tech/jl/961-get_ripe_config_public_o…
Browse files Browse the repository at this point in the history
…ptions

#961 Add getRipeConfigOptions methods
  • Loading branch information
joao-conde authored Jun 22, 2022
2 parents 8daac24 + 42ab9a8 commit 12f4e0a
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 40 additions & 0 deletions js/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,43 @@ export const getRipeWhiteAdminOptions = (environment, fallback = {}) => {
return fallback;
}
};

export const getRipeConfigOptions = (environment, fallback = {}) => {
switch (environment) {
case "ci":
case "test":
case "now":
case "now-branch":
case "sandbox":
case "stage":
return {
url: "https://master--ripe-config.netlify.app/"
};
case "production":
return {
url: "https://config.platforme.com/"
};
default:
return fallback;
}
};

export const getRipeConfigPublicOptions = (environment, fallback = {}) => {
switch (environment) {
case "ci":
case "test":
case "now":
case "now-branch":
case "sandbox":
case "stage":
return {
url: "https://master--ripe-config-public.netlify.app/"
};
case "production":
return {
url: "https://config-public.platforme.com/"
};
default:
return fallback;
}
};
92 changes: 92 additions & 0 deletions test/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,95 @@ 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/"
});
});

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() {
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/"
});
});

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/"
});
});
});

0 comments on commit 12f4e0a

Please sign in to comment.