-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split model tests into their own files for different methods
- Loading branch information
1 parent
ac63605
commit debc799
Showing
3 changed files
with
186 additions
and
70 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,66 @@ | ||
/// <reference path="../nodelib/node.js"/> | ||
/// <reference path="../nodelib/mocha.js"/> | ||
/// <reference path="../nodelib/should.js"/> | ||
/// <reference path="../index.js"/> | ||
|
||
var config = require('./config'); | ||
var Database = require('../index'); | ||
var Model = Database.Model; | ||
var Instance = Database.Instance; | ||
var should = require('should'); | ||
var Concoction = require('concoction'); | ||
|
||
describe('orm', function () { | ||
"use strict"; | ||
|
||
describe('Model', function () { | ||
var db = null; | ||
|
||
before(function (done) { | ||
db = new Database(config); | ||
db.connect(done); | ||
}); | ||
|
||
describe('database', function() { | ||
var model = null; | ||
|
||
before(function(done) { | ||
model = new Model(db, 'model', { | ||
name: /.+/ | ||
}, { | ||
preprocessors: [new Concoction.Rename({ _id: 'name' })] | ||
}); | ||
|
||
model.remove(function(err) { | ||
if(err) return done(err); | ||
|
||
model.create({ | ||
name: 'Demo1' | ||
}, function(err, instance) { | ||
if(err) return done(err); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('findOne', function() { | ||
it('should be able to locate a single object', function(done) { | ||
model.findOne({ name: 'Demo1' }, function(err, obj) { | ||
if(err) return done(err); | ||
should.exist(obj); | ||
obj.should.have.ownProperty('name', 'Demo1'); | ||
done(); | ||
}) | ||
}); | ||
|
||
it('should not throw an error if it couldn\'t find an object', function(done) { | ||
model.findOne({ name: 'NotFound' }, function(err, obj) { | ||
if(err) return done(err); | ||
should.not.exist(obj); | ||
done(); | ||
}) | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,83 @@ | ||
/// <reference path="../nodelib/node.js"/> | ||
/// <reference path="../nodelib/mocha.js"/> | ||
/// <reference path="../nodelib/should.js"/> | ||
/// <reference path="../index.js"/> | ||
|
||
var config = require('./config'); | ||
var Database = require('../index'); | ||
var Model = Database.Model; | ||
var Instance = Database.Instance; | ||
var should = require('should'); | ||
var Concoction = require('concoction'); | ||
|
||
describe('orm', function () { | ||
"use strict"; | ||
|
||
describe('Model', function () { | ||
var db = null; | ||
|
||
before(function (done) { | ||
db = new Database(config); | ||
db.connect(done); | ||
}); | ||
|
||
describe('database', function() { | ||
var model = null; | ||
|
||
before(function(done) { | ||
model = new Model(db, 'model', { | ||
name: /.+/ | ||
}, { | ||
preprocessors: [new Concoction.Rename({ _id: 'name' })] | ||
}); | ||
|
||
model.remove(done); | ||
}); | ||
|
||
describe('insertion', function() { | ||
|
||
it('should allow a single object to be inserted', function(done) { | ||
model.create({ | ||
name: 'Demo1' | ||
}, function(err, instance) { | ||
if(err) return done(err); | ||
instance.should.have.ownProperty('name', 'Demo1'); | ||
return done(); | ||
}); | ||
}); | ||
|
||
it('should have created the instance in the database', function(done) { | ||
model.count({ name: 'Demo1' }, function(err, number) { | ||
if(err) return done(err); | ||
number.should.eql(1); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should allow multiple objects to be inserted', function(done) { | ||
model.create([{ | ||
name: 'Demo2' | ||
}, { | ||
name: 'Demo3' | ||
}], function(err, instances) { | ||
if(err) return done(err); | ||
should(Array.isArray(instances)); | ||
instances[0].should.have.ownProperty('name', 'Demo2'); | ||
instances[1].should.have.ownProperty('name', 'Demo3'); | ||
return done(); | ||
}); | ||
}); | ||
|
||
it('should pass along DB errors', function(done) { | ||
model.create({ | ||
name: 'Demo1' | ||
}, function(err, inserted) { | ||
should.exist(err); | ||
should.not.exist(inserted); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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