Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = {};
Expand Down Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion test/playground/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
17 changes: 17 additions & 0 deletions test/switcher-integrated.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down