Browse Source

Increase coverage by adding tests for eval, drop database, db stats, create and drop users

saintedlama/travis-non-legacy
saintedlama 9 years ago
parent
commit
37c690b162
  1. 20
      test/test-db-stats.js
  2. 14
      test/test-drop-database.js
  3. 23
      test/test-eval.js
  4. 30
      test/test-user-create.js
  5. 25
      test/test-user-drop.js

20
test/test-db-stats.js

@ -0,0 +1,20 @@
var insert = require('./insert')
insert('db stats', [{
name: 'Squirtle', type: 'water'
}, {
name: 'Starmie', type: 'water'
}, {
name: 'Charmander', type: 'fire'
}, {
name: 'Lapras', type: 'water'
}], function (db, t) {
db.stats(function (err, stats) {
t.error(err, 'Should get stats without an error')
t.ok(stats.ok, 'OK flag should be set in result')
t.ok(stats.collections)
t.ok(stats.indexes)
t.end()
})
})

14
test/test-drop-database.js

@ -0,0 +1,14 @@
var test = require('./tape')
var mongojs = require('../index')
var db = mongojs('test', ['a'])
test('dropDatabase', function (t) {
db.dropDatabase(function (err) {
t.error(err, 'Should drop a connected database without an error')
db.close(function (err) {
t.error(err, 'Should close a connection to a dropped database')
t.end()
})
})
})

23
test/test-eval.js

@ -0,0 +1,23 @@
var test = require('./tape')
var mongojs = require('../index')
var db = mongojs('test', ['a'])
test('eval', function (t) {
var sum = function (x, y) {
return x + y
}
var failing = function () {
throw new Error('Does not work')
}
db.eval(sum, 1, 2, function (err, res) {
t.error(err, 'Should eval a function without an error')
t.equal(res, 3, 'Should eval sum function')
db.eval(failing, function (err) {
t.ok(err, 'Should error when eval a function with missing operand is called')
t.end()
})
})
})

30
test/test-user-create.js

@ -0,0 +1,30 @@
var test = require('./tape')
var mongojs = require('../index')
var db = mongojs('test', ['a'])
test('create user', function (t) {
// Ignore errors when dropping the user
db.dropUser('mongojs', function () {
db.createUser({
user: 'mongojs',
pwd: 'topsecret',
customData: { department: 'area51' },
roles: ['readWrite']
}, function (err, res) {
t.error(err, 'Should create a user without an error')
t.ok(res.ok)
db.createUser({
user: 'mongojs',
pwd: 'topsecret',
customData: { department: 'area51' },
roles: ['readWrite']
}, function (err) {
t.ok(err, 'Should yield an error when creating a duplicate user')
t.equal(err.code, 11000, 'Should yield a duplicate user error')
t.end()
})
})
})
})

25
test/test-user-drop.js

@ -0,0 +1,25 @@
var test = require('./tape')
var mongojs = require('../index')
var db = mongojs('test', ['a'])
test('drop user', function (t) {
// Ignore errors when dropping the user
db.dropUser('mongojs', function () {
db.createUser({
user: 'mongojs',
pwd: 'topsecret',
customData: { department: 'area51' },
roles: ['readWrite']
}, function (err, res) {
t.error(err, 'Should create a user without an error')
t.ok(res.ok)
db.dropUser('mongojs', function (err, res) {
t.error(err, 'Should drop an existing user without an error')
t.ok(res.ok)
t.end()
})
})
})
})
Loading…
Cancel
Save