Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Jan 2, 2016
1 parent 1ea57dd commit 5893a7a
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 1 deletion.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
146 changes: 146 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
@@ -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();
})
});
})
});
});

0 comments on commit 5893a7a

Please sign in to comment.