saintedlama
9 years ago
4 changed files with 62 additions and 7 deletions
@ -0,0 +1,39 @@ |
|||||
|
var test = require('./tape') |
||||
|
var mongojs = require('../') |
||||
|
var MongoClient = require('mongodb').MongoClient |
||||
|
|
||||
|
test('receive a mongodb db instance', function (t) { |
||||
|
MongoClient.connect('mongodb://localhost/test', function (err, mongoDb) { |
||||
|
t.error(err) |
||||
|
|
||||
|
var db = mongojs(mongoDb, ['a']) |
||||
|
var afterFind = function () { |
||||
|
db.a.remove(function (err) { |
||||
|
t.error(err) |
||||
|
t.equal(db.toString(), 'test', 'should expose database name') |
||||
|
|
||||
|
db.close(function (err) { |
||||
|
t.error(err) |
||||
|
t.end() |
||||
|
}) |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
var afterInsert = function (err) { |
||||
|
t.error(err) |
||||
|
|
||||
|
db.a.findOne(function (err, data) { |
||||
|
t.error(err) |
||||
|
t.equal(data.name, 'Pidgey') |
||||
|
afterFind() |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
var afterRemove = function (err) { |
||||
|
t.error(err) |
||||
|
db.a.insert({name: 'Pidgey'}, afterInsert) |
||||
|
} |
||||
|
|
||||
|
db.a.remove(afterRemove) |
||||
|
}) |
||||
|
}) |
@ -1,13 +1,13 @@ |
|||||
var test = require('./tape') |
var test = require('./tape') |
||||
var mongojs = require('../') |
var mongojs = require('../') |
||||
|
|
||||
test('receive a driver db or mongojs instance', function (t) { |
test('receive a mongojs instance', function (t) { |
||||
|
|
||||
var db = mongojs(mongojs('test', []), ['a']) |
var db = mongojs(mongojs('test', []), ['a']) |
||||
var afterFind = function () { |
var afterFind = function () { |
||||
db.a.remove(function (err) { |
db.a.remove(function (err) { |
||||
t.error(err) |
t.error(err) |
||||
t.equal(db.toString(), 'test') |
t.equal(db.toString(), 'test', 'should expose database name') |
||||
|
|
||||
db.close(function (err) { |
db.close(function (err) { |
||||
t.error(err) |
t.error(err) |
@ -0,0 +1,8 @@ |
|||||
|
var test = require('./tape') |
||||
|
var mongojs = require('../') |
||||
|
|
||||
|
test('db.toString', function (t) { |
||||
|
var db = mongojs('test', ['a']) |
||||
|
t.equal(db.toString(), 'test', 'toString should return database name') |
||||
|
t.end() |
||||
|
}) |
Loading…
Reference in new issue