Skip to content

Commit

Permalink
fixing test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
yawetse committed May 8, 2017
1 parent db6b32c commit fdab290
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 14 deletions.
10 changes: 5 additions & 5 deletions lib/init/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function configureLowkie() {
.then((db) => {
// console.log('connected db', db);
if (this.config.debug) {
console.log('LOWKIE: initialized configuration db');
this.logger.silly('LOWKIE: initialized configuration db');
}
})
.catch(reject);
Expand All @@ -28,12 +28,12 @@ function configureLowkie() {
});
lowkie.connection.on('connecting', (connectdata) => {
if (this.config.debug) {
console.log('LOWKIE: now trying to connect to configuration db');
this.logger.silly('LOWKIE: now trying to connect to configuration db');
}
});
lowkie.connection.once('connected', (connectdata) => {
if (this.config.debug) {
console.log('LOWKIE: connected to configuration db', { connectdata });
this.logger.silly('LOWKIE: connected to configuration db', { connectdata });
}
const configurationModel = lowkie.model('configuration', configSchemas.lowkie);
const CoreDataAdapter = this.core.data.create({
Expand All @@ -50,7 +50,7 @@ function configureLowkie() {
// });
this.datas.set('configuration', CoreDataAdapter);

console.log({ __CONFIG_DB }, 'config lowkie this', this);
this.logger.silly({ __CONFIG_DB }, 'config lowkie this', this);
resolve(true);
});

Expand Down Expand Up @@ -82,7 +82,7 @@ function configureLowkie() {
}

function configureMongoose() {
console.log('config lowkie this', this);
// console.log('config lowkie this', this);

return new Promise((resolve, reject) => {
try {
Expand Down
12 changes: 7 additions & 5 deletions lib/periodicClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ class periodic {
this.extensions = new Map();
this.datas = new Map();
this.logger = console;
this.logger.silly = console.log;
this.logger.debug = console.log;
this.logger.info = console.info;
this.logger.warn = console.log;
this.logger.error = console.error;
// this.db = undefined;
this.app = {}; //express app
this.core = {
data: CoreData,
};

// this.controller = peroidicController.bind(this);
// this.container = peroidicContainer.bind(this);
// this.extension = peroidicExtension.bind(this);
Expand Down Expand Up @@ -66,11 +72,7 @@ class periodic {
// return Promisie.series([(resolve, reject) => {

// }]);
this.logger.silly = console.log;
this.logger.debug = console.log;
this.logger.info = console.info;
this.logger.warn = console.log;
this.logger.error = console.error;


return Promisie.series([
periodicInit.timer.startTimer,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"lowkie": "^0.1.2",
"moment": "^2.18.1",
"mongoose": "^4.9.7",
"periodicjs.core.data": "^0.1.2",
"periodicjs.core.data": "^0.2.0",
"pluralize": "^4.0.0",
"promisie": "^1.6.1",
"proxy-polyfill": "0.1.6",
Expand Down Expand Up @@ -153,6 +153,7 @@
"jsdoc": "^3.3.2",
"mocha": "^2.2.5",
"mocha-lcov-reporter": "^1.2.0",
"mocha-sinon": "^2.0.0",
"sinon": "^1.17.4",
"sinon-chai": "^2.8.0",
"supertest": "^1.0.1",
Expand Down
57 changes: 54 additions & 3 deletions test/unit/periodic_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@
const path = require('path');
const events = require('events');
const chai = require('chai');
const sinon = require('sinon');
const fs = require('fs-extra');
const expect = require('chai').expect;
let periodic = require('../../index');
// let periodicSchema = require('../../lib/schema');
let periodicClass = require('../../lib/periodicClass');
chai.use(require('sinon-chai'));
require('mocha-sinon');
// const sinon = require('sinon');

const testPathDir = path.resolve(__dirname, '../mock/spec/periodic');
const initTestPathDir = path.join(testPathDir, 'initTest');


describe('periodic', function () {
this.timeout(10000);
before('initialize test periodic dir', (done) => {
fs.ensureDir(initTestPathDir)
.then(() => {
done();
}).catch(done);
});
describe('Represents a singleton module', function () {
it('should always reference the same instance of periodic when required', function () {
let periodic2 = require('../../index');
expect(periodic)
.to.deep.equal(periodic2)
.and.to.be.an.instanceof(periodicClass);
});
it('should be implemented with configurable default settings', () => {
expect(Object.keys(periodic.config).length).to.be.greaterThan(0);
});

// it('should export schema types', () => {
// expect(periodic.Schema.Types).to.be.an('object');
// expect(periodic.Schema.Types).to.have.property('String');
Expand All @@ -41,4 +55,41 @@ describe('periodic', function () {
// expect(periodic.Schema(testUserSchema)).to.be.an.an('object');
// });
});
describe('Manages initialization configuration', () => {
// beforeEach(function() {
// // this.sinon.stub(console, 'log');
// });
it('should be implemented with configurable default settings', () => {
expect(Object.keys(periodic.config).length).to.be.greaterThan(0);
});
it('should allow for overwriteable configs', (done) => {
let spy = sinon.spy();
periodic.logger.silly = spy;
periodic.logger.debug = spy;
periodic.logger.info = spy;
periodic.logger.warn = spy;
periodic.logger.error = spy;

// this.sinon.stub(console, 'log');

// console.log('this.sinon', this.sinon);
periodic.init({
debug: true,
app_root: initTestPathDir,
})
.then((result) => {
expect(periodic.config.debug).to.be.true;
expect(periodic.config.app_root).to.eql(initTestPathDir);
// console.log({ result, });
done();
})
.catch(done);
});
})
after('remove test periodic dir', (done) => {
fs.remove(initTestPathDir)
.then(() => {
done();
}).catch(done);
});
});

0 comments on commit fdab290

Please sign in to comment.