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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "switcher-client",
"version": "3.1.1",
"version": "3.1.2",
"description": "Client JS SDK for working with Switcher-API",
"main": "./src/index.js",
"types": "./src/index.d.ts",
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.1
sonar.projectVersion=3.1.2
sonar.links.homepage=https://github.com/switcherapi/switcher-client-master

sonar.javascript.lcov.reportPaths=coverage/lcov.info
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class Switcher {
Switcher.context, this._key, this._input, showReason);

if (Switcher.options.logger)
ExecutionLogger.add(this._key, this._input, responseCriteria);
ExecutionLogger.add(responseCriteria, this._key, this._input);

return responseCriteria.result;
}
Expand All @@ -287,7 +287,7 @@ class Switcher {
if (this._nextRun < Date.now()) {
this._nextRun = Date.now() + this._delay;
services.checkCriteria(Switcher.context, this._key, this._input, showReason)
.then(response => ExecutionLogger.add(this._key, this._input, response));
.then(response => ExecutionLogger.add(response, this._key, this._input));
}

return ExecutionLogger.getExecution(this._key, this._input).response.result;
Expand All @@ -307,7 +307,7 @@ class Switcher {
this._key, this._input, Switcher.snapshot);

if (Switcher.options.logger)
ExecutionLogger.add(this._key, response);
ExecutionLogger.add(response, this._key, this._input);

return response.result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/executionLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ExecutionLogger {
* @param input
* @param response
*/
static add(key, input, response) {
static add(response, key, input) {
for (let index = 0; index < logger.length; index++) {
const log = logger[index];
if (log.key === key && JSON.stringify(log.input) === JSON.stringify(input)) {
Expand Down
17 changes: 0 additions & 17 deletions test/fixture/utils.js

This file was deleted.

39 changes: 39 additions & 0 deletions test/helper/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function given(fetchStub, order, expect) {
fetchStub.onCall(order).returns(Promise.resolve(expect));
}

function givenError(fetchStub, order, expect) {
fetchStub.onCall(order).throws(expect);
}

function throws(fetchStub, expect) {
fetchStub.throws(expect);
}

const generateAuth = (token, seconds) => {
return {
token,
exp: (Date.now() + (seconds * 1000)) / 1000
};
};

const generateStatus = (status) => {
return {
status
};
};

const generateResult = (result) => {
return {
result
};
};

module.exports = {
given,
givenError,
throws,
generateAuth,
generateStatus,
generateResult
};
2 changes: 1 addition & 1 deletion test/playground/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ const testWatchSnapshot = async () => {
(err) => console.log(err));
};

testWatchSnapshot();
testSimpleAPICall(true);
31 changes: 17 additions & 14 deletions test/switcher-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ const { StrategiesType } = require('../src/lib/snapshot');

describe('E2E test - Switcher offline:', function () {
let switcher;
const apiKey = '[api_key]';
const domain = 'Business';
const component = 'business-service';
const environment = 'default';
const url = 'http://localhost:3000';

const contextSettings = {
apiKey: '[api_key]',
domain: 'Business',
component: 'business-service',
environment: 'default',
url: 'http://localhost:3000'
};

this.beforeAll(async function() {
Switcher.buildContext({ url, apiKey, domain, component, environment }, {
Switcher.buildContext(contextSettings, {
offline: true, logger: true
});

Expand Down Expand Up @@ -96,7 +99,7 @@ describe('E2E test - Switcher offline:', function () {

const result = await switcher.isItOn();
assert.isFalse(result);
assert.equal(Switcher.getLogger('FF2FOR2023')[0].input.reason,
assert.equal(Switcher.getLogger('FF2FOR2023')[0].response.reason,
`Strategy '${StrategiesType.PAYLOAD}' does not agree`);
});

Expand All @@ -108,28 +111,28 @@ describe('E2E test - Switcher offline:', function () {

const result = await switcher.isItOn();
assert.isFalse(result);
assert.equal(Switcher.getLogger('FF2FOR2020')[0].input.reason,
assert.equal(Switcher.getLogger('FF2FOR2020')[0].response.reason,
`Strategy '${StrategiesType.NETWORK}' does not agree`);
});

it('should be invalid - Input not provided', async function () {
const result = await switcher.isItOn('FF2FOR2020');
assert.isFalse(result);
assert.equal(Switcher.getLogger('FF2FOR2020')[0].input.reason,
assert.equal(Switcher.getLogger('FF2FOR2020')[0].response.reason,
`Strategy '${StrategiesType.NETWORK}' did not receive any input`);
});

it('should be invalid - Switcher config disabled', async function () {
const result = await switcher.isItOn('FF2FOR2031');
assert.isFalse(result);
assert.equal(Switcher.getLogger('FF2FOR2031')[0].input.reason,
assert.equal(Switcher.getLogger('FF2FOR2031')[0].response.reason,
'Config disabled');
});

it('should be invalid - Switcher group disabled', async function () {
const result = await switcher.isItOn('FF2FOR2040');
assert.isFalse(result);
assert.equal(Switcher.getLogger('FF2FOR2040')[0].input.reason,
assert.equal(Switcher.getLogger('FF2FOR2040')[0].response.reason,
'Group disabled');
});

Expand Down Expand Up @@ -163,7 +166,7 @@ describe('E2E test - Switcher offline:', function () {

it('should enable test mode which will prevent a snapshot to be watchable', async function () {
//given
Switcher.buildContext({ url, apiKey, domain, component, environment }, {
Switcher.buildContext(contextSettings, {
offline: true, logger: true
});

Expand All @@ -179,7 +182,7 @@ describe('E2E test - Switcher offline:', function () {
it('should be invalid - Offline mode cannot load snapshot from an invalid path', async function () {
this.timeout(3000);

Switcher.buildContext({ url, apiKey, domain, component, environment }, {
Switcher.buildContext(contextSettings, {
offline: true,
snapshotLocation: '//somewhere/'
});
Expand All @@ -192,7 +195,7 @@ describe('E2E test - Switcher offline:', function () {
it('should be valid - Offline mode', async function () {
this.timeout(3000);

Switcher.buildContext({ url, apiKey, domain, component, environment }, {
Switcher.buildContext(contextSettings, {
offline: true,
snapshotLocation: 'generated-snapshots/'
});
Expand Down
Loading