1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | 'use strict';
|
8 |
|
9 |
|
10 | const should = require('./init.js');
|
11 |
|
12 | const db = getSchema();
|
13 | const slave = getSchema();
|
14 | let Model, SlaveModel;
|
15 |
|
16 | describe('dataSource', function() {
|
17 | it('should define Model', function() {
|
18 | Model = db.define('Model');
|
19 | Model.dataSource.should.eql(db);
|
20 | const m = new Model;
|
21 | m.getDataSource().should.eql(db);
|
22 | });
|
23 |
|
24 | it('should clone existing model', function() {
|
25 | SlaveModel = slave.copyModel(Model);
|
26 | SlaveModel.dataSource.should.equal(slave);
|
27 | slave.should.not.equal(db);
|
28 | const sm = new SlaveModel;
|
29 | sm.should.be.instanceOf(Model);
|
30 | sm.getDataSource().should.not.equal(db);
|
31 | sm.getDataSource().should.equal(slave);
|
32 | });
|
33 |
|
34 | it('should automigrate', function(done) {
|
35 | db.automigrate(done);
|
36 | });
|
37 |
|
38 | it('should create transaction', function(done) {
|
39 | const tr = db.transaction();
|
40 | tr.connected.should.be.false;
|
41 | tr.connecting.should.be.false;
|
42 | let called = false;
|
43 | tr.models.Model.create(Array(3), function() {
|
44 | called = true;
|
45 | });
|
46 | tr.connected.should.be.false;
|
47 | tr.connecting.should.be.true;
|
48 |
|
49 | db.models.Model.count(function(err, c) {
|
50 | should.not.exist(err);
|
51 | should.exist(c);
|
52 | c.should.equal(0);
|
53 | called.should.be.false;
|
54 | tr.exec(function() {
|
55 | setTimeout(function() {
|
56 | called.should.be.true;
|
57 | db.models.Model.count(function(err, c) {
|
58 | c.should.equal(3);
|
59 | done();
|
60 | });
|
61 | }, 100);
|
62 | });
|
63 | });
|
64 | });
|
65 | });
|