loopback-datasource-juggler/test/schema.test.js

58 lines
1.7 KiB
JavaScript
Raw Normal View History

2013-04-06 10:57:12 +00:00
// This test written in mocha+should.js
var should = require('./init.js');
2013-04-04 22:12:34 +00:00
var db = getSchema(), slave = getSchema(), Model, SlaveModel;
describe('dataSource', function() {
2013-04-04 22:12:34 +00:00
it('should define Model', function() {
Model = db.define('Model');
Model.dataSource.should.eql(db);
2013-04-04 22:12:34 +00:00
var m = new Model;
2013-10-31 17:51:33 +00:00
m.getDataSource().should.eql(db);
2013-04-04 22:12:34 +00:00
});
it('should clone existing model', function() {
SlaveModel = slave.copyModel(Model);
SlaveModel.dataSource.should.eql(slave);
2013-04-04 22:12:34 +00:00
slave.should.not.eql(db);
var sm = new SlaveModel;
sm.should.be.instanceOf(Model);
2013-10-31 17:51:33 +00:00
sm.getDataSource().should.not.eql(db);
sm.getDataSource().should.eql(slave);
2013-04-04 22:12:34 +00:00
});
it('should automigrate', function(done) {
db.automigrate(done);
});
it('should create transaction', function(done) {
var tr = db.transaction();
tr.connected.should.be.false;
tr.connecting.should.be.false;
var called = false;
tr.models.Model.create(Array(3), function () {
called = true;
});
tr.connected.should.be.false;
tr.connecting.should.be.true;
db.models.Model.count(function(err, c) {
should.not.exist(err);
should.exist(c);
c.should.equal(0);
called.should.be.false;
tr.exec(function () {
setTimeout(function() {
called.should.be.true;
db.models.Model.count(function(err, c) {
c.should.equal(3);
done();
});
}, 100);
});
});
});
});