saintedlama
9 years ago
5 changed files with 112 additions and 0 deletions
@ -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() |
|||
}) |
|||
}) |
@ -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() |
|||
}) |
|||
}) |
|||
}) |
@ -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() |
|||
}) |
|||
}) |
|||
}) |
@ -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() |
|||
}) |
|||
}) |
|||
}) |
|||
}) |
@ -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…
Reference in new issue