mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
fixed unit tests
This commit is contained in:
parent
237ac7731c
commit
4aa97b159c
@ -37,13 +37,13 @@
|
||||
"start:dev:pg-chain": "export DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@localhost:$PGPORT/postgres ; db-migrate up && npm run start:dev",
|
||||
"db-migrate": "db-migrate up",
|
||||
"db-migrate:down": "db-migrate down",
|
||||
"test": "export PORT=4243 ; mocha test/**/*.js && npm run test:coverage",
|
||||
"test": "export PORT=4243 ; mocha --recursive test && npm run test:coverage",
|
||||
"test:unit": "mocha test/unit/**/*.js ",
|
||||
"test:ci": "npm run db-migrate && npm run test",
|
||||
"test:watch": "mocha --watch test test/*",
|
||||
"test:pg-virtualenv": "pg_virtualenv npm run test:pg-virtualenv-chai",
|
||||
"test:pg-virtualenv-chain": "export TEST_DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@localhost:$PGPORT/postgres ; npm run db-migrate-testdb && npm test",
|
||||
"test:coverage": "istanbul cover ./node_modules/mocha/bin/_mocha test/**/*.js --report lcovonly -- -R spec",
|
||||
"test:coverage": "istanbul cover ./node_modules/mocha/bin/_mocha test --report lcovonly -- -R spec --recursive",
|
||||
"test:coverage-report": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -1,25 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const clientMetricsStore = require('./mocks/fake-metrics-store');
|
||||
const featureToggleStore = require('./mocks/fake-feature-toggle-store');
|
||||
const strategyStore = require('./mocks/fake-strategies-store');
|
||||
|
||||
const supertest = require('supertest');
|
||||
const BPromise = require('bluebird');
|
||||
BPromise.promisifyAll(supertest);
|
||||
const assert = require('assert');
|
||||
const sinon = require('sinon');
|
||||
|
||||
let request;
|
||||
let featureDb;
|
||||
|
||||
describe('Unit: The features api', () => {
|
||||
beforeEach(done => {
|
||||
featureDb = createFeatureDb();
|
||||
featureToggleStore.reset();
|
||||
|
||||
const app = require('../../../app')({
|
||||
baseUriPath: '',
|
||||
db: sinon.stub(),
|
||||
eventDb: sinon.stub(),
|
||||
eventStore: sinon.stub(),
|
||||
featureDb,
|
||||
strategyDb: sinon.stub(),
|
||||
stores: {
|
||||
db: sinon.stub(),
|
||||
eventStore: sinon.stub(),
|
||||
featureToggleStore,
|
||||
clientMetricsStore,
|
||||
strategyStore,
|
||||
clientStrategyStore: sinon.stub(),
|
||||
clientInstanceStore: sinon.stub(),
|
||||
},
|
||||
});
|
||||
|
||||
request = supertest(app);
|
||||
@ -38,7 +43,7 @@ describe('Unit: The features api', () => {
|
||||
});
|
||||
|
||||
it('should get one getFeature', (done) => {
|
||||
featureDb.addFeature( { name: 'test', strategies: [{ name: 'default' }] } );
|
||||
featureToggleStore.addFeature( { name: 'test', strategies: [{ name: 'default' }] } );
|
||||
|
||||
request
|
||||
.get('/features')
|
||||
@ -51,7 +56,7 @@ describe('Unit: The features api', () => {
|
||||
});
|
||||
|
||||
it('should add version numbers for /features', (done) => {
|
||||
featureDb.addFeature( { name: 'test', strategies: [{ name: 'default' }] } );
|
||||
featureToggleStore.addFeature( { name: 'test', strategies: [{ name: 'default' }] } );
|
||||
|
||||
request
|
||||
.get('/features')
|
||||
@ -63,11 +68,3 @@ describe('Unit: The features api', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function createFeatureDb () {
|
||||
const _features = [];
|
||||
return {
|
||||
getFeatures: () => BPromise.resolve(_features),
|
||||
addFeature: (feature) => _features.push(feature),
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const _features = [];
|
||||
|
||||
module.exports = {
|
||||
getFeatures: () => Promise.resolve(_features),
|
||||
addFeature: (feature) => _features.push(feature),
|
||||
reset: () => {
|
||||
_features.lengyh = 0;
|
||||
},
|
||||
};
|
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
getMetricsLastHour: () => Promise.resolve([]),
|
||||
};
|
@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const _strategies = [{ name: 'default', parameters: {} }];
|
||||
|
||||
|
||||
module.exports = {
|
||||
getStrategies: () => Promise.resolve(_strategies),
|
||||
addStrategy: (strat) => _strategies.push(strat),
|
||||
reset: () => {
|
||||
_strategies.length = 0;
|
||||
},
|
||||
};
|
@ -1,25 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const clientMetricsStore = require('./mocks/fake-metrics-store');
|
||||
const featureToggleStore = require('./mocks/fake-feature-toggle-store');
|
||||
const strategyStore = require('./mocks/fake-strategies-store');
|
||||
|
||||
const supertest = require('supertest');
|
||||
const BPromise = require('bluebird');
|
||||
BPromise.promisifyAll(supertest);
|
||||
const assert = require('assert');
|
||||
const sinon = require('sinon');
|
||||
|
||||
let request;
|
||||
let stratDb;
|
||||
|
||||
describe('Unit: The strategies api', () => {
|
||||
beforeEach(done => {
|
||||
stratDb = createStrategyDb();
|
||||
strategyStore.reset();
|
||||
|
||||
const app = require('../../../app')({
|
||||
baseUriPath: '',
|
||||
db: sinon.stub(),
|
||||
eventDb: sinon.stub(),
|
||||
eventStore: sinon.stub(),
|
||||
featureDb: sinon.stub(),
|
||||
strategyDb: stratDb,
|
||||
stores: {
|
||||
db: sinon.stub(),
|
||||
eventStore: sinon.stub(),
|
||||
featureToggleStore,
|
||||
clientMetricsStore,
|
||||
strategyStore,
|
||||
clientStrategyStore: sinon.stub(),
|
||||
clientInstanceStore: sinon.stub(),
|
||||
},
|
||||
});
|
||||
|
||||
request = supertest(app);
|
||||
@ -37,11 +42,3 @@ describe('Unit: The strategies api', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function createStrategyDb () {
|
||||
const _strategies = [{ name: 'default', parameters: {} }];
|
||||
return {
|
||||
getStrategies: () => BPromise.resolve(_strategies),
|
||||
addStrategy: (strat) => _strategies.push(strat),
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user