-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase coverage by adding tests for eval, drop database, db stats, …
…create and drop users
- Loading branch information
1 parent
f49c38e
commit 37c690b
Showing
5 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) | ||
}) | ||
}) | ||
}) |