From 3ee0c75b926c3f0857df2628a0f5a366fa5f90e8 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Wed, 14 Sep 2022 22:35:57 -0700 Subject: [PATCH] Closes #122 - Removed heroku as default API url --- README.md | 2 +- package.json | 8 ++++---- sonar-project.properties | 2 +- src/index.js | 7 +++++-- test/playground/index.js | 2 +- test/switcher-integrated.test.js | 17 +++++++++++++++++ 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 78bf72a..57bd3a1 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ const apiKey = '[API_KEY]'; const environment = 'default'; const domain = 'My Domain'; const component = 'MyApp'; -const url = 'https://switcher-api.herokuapp.com'; +const url = 'https://switcherapi.com/api'; ``` - **apiKey**: Switcher-API key generated to your component. diff --git a/package.json b/package.json index 080ccd1..a7e3bc8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "switcher-client", - "version": "3.1.2", + "version": "3.1.3", "description": "Client JS SDK for working with Switcher-API", "main": "./src/index.js", "types": "./src/index.d.ts", @@ -30,12 +30,12 @@ "node-fetch": "^2.6.7" }, "devDependencies": { - "@typescript-eslint/eslint-plugin": "^5.32.0", - "@typescript-eslint/parser": "^5.32.0", + "@typescript-eslint/eslint-plugin": "^5.37.0", + "@typescript-eslint/parser": "^5.37.0", "babel-eslint": "^10.1.0", "chai": "^4.3.6", "chai-as-promised": "^7.1.1", - "eslint": "^8.21.0", + "eslint": "^8.23.1", "mocha": "^10.0.0", "mocha-sonarqube-reporter": "^1.0.2", "nyc": "^15.1.0", diff --git a/sonar-project.properties b/sonar-project.properties index aea43fe..6d09125 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,7 +1,7 @@ sonar.projectKey=switcherapi_switcher-client-master sonar.projectName=switcher-client-master sonar.organization=switcherapi -sonar.projectVersion=3.1.2 +sonar.projectVersion=3.1.3 sonar.links.homepage=https://github.com/switcherapi/switcher-client-master sonar.javascript.lcov.reportPaths=coverage/lcov.info diff --git a/src/index.js b/src/index.js index 1d43f0b..11ac33b 100644 --- a/src/index.js +++ b/src/index.js @@ -18,7 +18,6 @@ const { checkPayload } = require('./lib/middlewares/check'); -const DEFAULT_URL = 'https://switcher-api.herokuapp.com'; const DEFAULT_ENVIRONMENT = 'default'; const DEFAULT_SNAPSHOT_LOCATION = './snapshot/'; const DEFAULT_RETRY_TIME = '5m'; @@ -41,8 +40,8 @@ class Switcher { this.snapshot = undefined; this.context = {}; this.context = context; + this.context.url = context.url; this.context.environment = context.environment || DEFAULT_ENVIRONMENT; - this.context.url = context.url || DEFAULT_URL; // Default values this.options = {}; @@ -218,6 +217,10 @@ class Switcher { async validate() { let errors = []; + if (!Switcher.context.url) { + errors.push('Missing API url field'); + } + if (!Switcher.context.apiKey) { errors.push('Missing API Key field'); } diff --git a/test/playground/index.js b/test/playground/index.js index 8042eda..f53d7ef 100644 --- a/test/playground/index.js +++ b/test/playground/index.js @@ -9,7 +9,7 @@ const apiKey = 'JDJiJDA4JEFweTZjSTR2bE9pUjNJOUYvRy9raC4vRS80Q2tzUnk1d3o1aXFmS2o5 const domain = 'Playground'; const component = 'switcher-playground'; const environment = 'default'; -const url = 'https://switcher-api.herokuapp.com'; +const url = 'https://switcherapi.com/api'; let switcher; diff --git a/test/switcher-integrated.test.js b/test/switcher-integrated.test.js index c09586d..8b08b46 100644 --- a/test/switcher-integrated.test.js +++ b/test/switcher-integrated.test.js @@ -264,6 +264,23 @@ describe('Integrated test - Switcher:', function () { ])); }); + it('should be invalid - Missing API url field', async function () { + // given + clientAuth.returns(generateAuth('[auth_token]', 5)); + + // test + Switcher.buildContext({ url: undefined, apiKey: 'apiKey', domain: 'domain', component: 'component', environment: 'default' }); + let switcher = Switcher.factory(); + + await switcher.prepare('MY_FLAG', [ + checkValue('User 1'), + checkNetwork('192.168.0.1') + ]); + + await assert.isRejected(switcher.isItOn(), + 'Something went wrong: Missing API url field'); + }); + it('should be invalid - Missing API Key field', async function () { // given clientAuth.returns(generateAuth('[auth_token]', 5));