Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Added tests and coverage reports
Browse files Browse the repository at this point in the history
  • Loading branch information
achhabra2 committed Sep 16, 2017
1 parent f260516 commit f7ba3e9
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 47 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Inquire Cisco Spark Bot
#### Written by Aman Chhabra
[![Build Status](https://travis-ci.org/achhabra2/inquire.svg?branch=master)](https://travis-ci.org/achhabra2/inquire)
[![Coverage Status](https://coveralls.io/repos/github/achhabra2/inquire/badge.svg?branch=master)](https://coveralls.io/github/achhabra2/inquire?branch=master)
[![GitHub stars](https://img.shields.io/github/stars/achhabra2/inquire.svg)](https://github.com/achhabra2/inquire/stargazers)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/achhabra2/inquire/master/LICENSE)
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/achhabra2/inquire)
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
},
"scripts": {
"start": "node ./src/server.js",
"test": "mocha --timeout 5000",
"test": "nyc --reporter=html --reporter=text mocha",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"devDependencies": {
"chai-as-promised": "^7.1.1",
"chai-things": "^0.2.0",
"coveralls": "^2.13.1",
"istanbul": "^0.4.5",
"nyc": "^11.2.1",
Expand Down
10 changes: 2 additions & 8 deletions src/qnaApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

const Room = require( './qnaModel' ).Room;
const Question = require( './qnaModel' ).Question;
const User = require( './userModel' )
const Spark = require( 'ciscospark' ).init( {
credentials: {
authorization: {
access_token: process.env.access_token
}
}
} );
const User = require( './userModel' );
const Spark = require( 'ciscospark/env' );

var router = express.Router();

Expand Down
9 changes: 5 additions & 4 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ mongoose.Promise = global.Promise;
if(process.env.MONGODB_URI)
process.env.mongo = process.env.MONGODB_URI

mongoose.connect( process.env.mongo ).then( ( err ) => {
mongoose.connect( process.env.mongo,
{useMongoClient: true}).then( ( db ) => {
debug('Connected to MongoDB');
if ( err )
console.error( err );
} );
} ).catch(err => {
console.error(err);
})


// Create the Botkit controller, which controls all instances of the bot.
Expand Down
45 changes: 45 additions & 0 deletions test/controller.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const fs = require('fs');
if (fs.existsSync('./.env')) {
console.log('Found env file');
const env = require('node-env-file');
env('./.env');
}

const chai = require('chai');
chai.should();
const chaiAsPromised = require("chai-as-promised");

chai.use(chaiAsPromised);
chai.use(require('chai-things'));

const qnaController = require('../src/qnaController');

var mongoose = require('mongoose');
mongoose.Promise = global.Promise;

describe('Controller ', function () {
it('Should connect to MongoDB', function (done) {
if (!mongoose.connection.readyState)
mongoose.connect(process.env.mongo, {
useMongoClient: true});
mongoose.connection.once('open', function () {
mongoose.connection.readyState.should.equal(1);
done();
});
});
});

describe('Function: Format Text', function () {
it('Should remove bot name from message.text', function () {
let message = {
text: `${process.env.bot_name} test`
}
qnaController.formatText(message).text.should.equal(' test')
});
});

describe('Controller Database Functions', function() {
it('Should GET MOTDs', function() {
return qnaController.getMotd().should.eventually.be.an('array');
});
});
21 changes: 0 additions & 21 deletions test/qnaController.test.js

This file was deleted.

Empty file added test/router.test.js
Empty file.
14 changes: 1 addition & 13 deletions test/server.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const chai = require('chai');
const app = require('../src/server');
const sinon = require('sinon');

chai.should();

const request = require('supertest');
var app = require('../src/server');

const helloJSON = {
"id": "Y2lzY29zcGFyazovL3VzL1dFQkhPT0svMjYzODJlZTktZjhhMC00MDlmLTg2NjUtNTk3MjAxZjBhYWU3",
Expand Down Expand Up @@ -97,16 +97,4 @@ describe('Bot Server', function () {
.send(webhookJSON)
.expect(200)
});
it('Should respond to HELLO command', function(done) {
done();
});
it('Should respond to HELP command. ', function(done) {
done();
});
it('Should respond to OPEN command', function(done) {
done();
});
it('Should respond to LIST command', function(done) {
done();
});
});
55 changes: 55 additions & 0 deletions test/skills.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const chai = require('chai');
chai.should()

const sinon = require('sinon');
const expect = chai.expect;



describe('Hello Skills Test', function() {
it('Should respond to Hello', function() {
let mdMessage = 'Welcome. I am the *Inquire Bot*. I will help you ask questions and get answers! Please refer to the ``help`` command for more information. ';
let bot = {
reply: function() {

}
};
let mBot = sinon.mock(bot);
let controller = {
hears: function(string1, string2, callback) {
}
};
let message = 'Hello';
let mController = sinon.mock(controller);
mController.expects('hears').once().withArgs(sinon.match.array, sinon.match.string, sinon.match.func).yields(bot, message);
mBot.expects('reply').withArgs(sinon.match.string, sinon.match({markdown: mdMessage}));
const hello = require('../src/skills/hello')(controller);
mBot.verify();
mController.verify();
})
});

describe('Help Skills Test', function() {
it('Should respond to Help', function() {
let bot = {
reply: function() {

},
startPrivateConversation: function() {
}
};
let mBot = sinon.mock(bot);
let controller = {
hears: function(string1, string2, callback) {
}
};
let message = 'Hello';
let mController = sinon.mock(controller);
mController.expects('hears').atLeast(2).withArgs(sinon.match.array, sinon.match.string, sinon.match.func).yields(bot, message);
mBot.expects('reply').atLeast(2).withArgs(sinon.match.string, sinon.match({markdown: sinon.match.string}));
mBot.expects('startPrivateConversation').withArgs(sinon.match.string, sinon.match.func);
const hello = require('../src/skills/help')(controller);
mBot.verify();
mController.verify();
})
});

0 comments on commit f7ba3e9

Please sign in to comment.