From 5893a7a5e38ab44d036d9a6ca067e8874e9e9b91 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Sun, 3 Jan 2016 00:58:53 +0200 Subject: [PATCH] Add tests --- package.json | 6 +- tests/index.js | 146 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 tests/index.js diff --git a/package.json b/package.json index 8f41311..0b5b16a 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "src/index.js", "scripts": { "start": "node src/index.js", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "mocha tests/*.js" }, "repository": { "type": "git", @@ -19,5 +19,9 @@ "homepage": "https://github.com/howdyai/botkit-storage-mongo#readme", "dependencies": { "monk": "^1.0.1" + }, + "devDependencies": { + "mocha": "^2.3.4", + "should": "^8.0.2" } } diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 0000000..6e0b589 --- /dev/null +++ b/tests/index.js @@ -0,0 +1,146 @@ +var should = require('should'); + +var testObject = { + id: 'test1', + foo: 'bar0' + }, + testObject2 = { + id: 'test2', + foo: 'bar1' + }; + +var mongodbDriver = require('../src/index.js')({ + mongoUri: 'mongodb://127.0.0.1:27017/tests' +}); + +describe('Users', function() { + it('should be created', function(done) { + mongodbDriver.users.save(testObject, function(err) { + (err === null).should.be.true; + + done(); + }); + }); + + it('should get a user', function(done) { + mongodbDriver.users.save(testObject, function(err, data) { + (err === null).should.be.true; + + mongodbDriver.users.get(data._id, function(err, data) { + (err === null).should.be.true; + + data.foo.should.equal(testObject.foo); + done(); + }); + }); + }); + + it('should get multiple users', function(done) { + var first, second; + mongodbDriver.users.save(testObject, function(err, data) { + (err === null).should.be.true; + first = data; + + mongodbDriver.users.save(testObject2, function(err, data) { + (err === null).should.be.true; + + second = data; + + mongodbDriver.users.all(function(err, data) { + (err === null).should.be.true; + + data.should.have.length(2); + done(); + }) + }); + }) + }); +}); + +describe('Channels', function() { + it('should be created', function(done) { + mongodbDriver.users.save(testObject, function(err) { + (err === null).should.be.true; + + done(); + }); + }); + + it('should get a channel', function(done) { + mongodbDriver.channels.save(testObject, function(err, data) { + (err === null).should.be.true; + + mongodbDriver.channels.get(data._id, function(err, data) { + (err === null).should.be.true; + + data.foo.should.equal(testObject.foo); + done(); + }); + }); + }); + + it('should get multiple channels', function(done) { + var first, second; + mongodbDriver.channels.save(testObject, function(err, data) { + (err === null).should.be.true; + first = data; + + mongodbDriver.channels.save(testObject2, function(err, data) { + (err === null).should.be.true; + + second = data; + + mongodbDriver.users.all(function(err, data) { + (err === null).should.be.true; + + data.should.have.length(2); + done(); + }) + }); + }) + }); +}); + +describe('Teams', function() { + it('should be created', function(done) { + mongodbDriver.teams.save(testObject, function(err) { + (err === null).should.be.true; + + done(); + }); + }); + + it('should get a team', function(done) { + mongodbDriver.teams.save(testObject, function(err, data) { + (err === null).should.be.true; + + mongodbDriver.teams.get(data._id, function(err, data) { + (err === null).should.be.true; + + data.foo.should.equal(testObject.foo); + done(); + }); + }); + }); + + it('should get multiple teams', function(done) { + var first, second; + + mongodbDriver.teams.save(testObject, function(err, data) { + (err === null).should.be.true; + first = data; + + mongodbDriver.teams.save(testObject2, function(err, data2) { + (err === null).should.be.true; + second = data2; + + mongodbDriver.teams.all(function(err, data) { + (err === null).should.be.true; + + data.should.have.length(2); + done(); + }) + }); + }) + }); +});