findAndCountAll.test.js
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, current = Support.sequelize
, sinon = require('sinon')
, DataTypes = require(__dirname + '/../../../lib/data-types')
, _ = require('lodash');
describe(Support.getTestDialectTeaser('Model'), function() {
describe('method findAndCountAll', function () {
var Model = current.define('model', {
name: DataTypes.STRING
}, { timestamps: false });
var Model2 = current.define('model2', {
name: DataTypes.STRING
}, { timestamps: false });
Model.hasMany(Model2);
Model2.belongsTo(Model);
before(function () {
this.stub = sinon.stub(current.getQueryInterface(), 'select', function () {
return Model.build({});
});
this.stubRaw = sinon.stub(current.getQueryInterface(), 'rawSelect', function () {
return Model.build({});
});
});
beforeEach(function () {
this.stub.reset();
this.stubRaw.reset();
});
after(function () {
this.stub.restore();
this.stubRaw.restore();
});
it('properly clones options values', function() {
var options = {
includes: [
{ model: 'model2', where: {
name: 'hello'
}}
]
};
var optionsClones = _.cloneDeep(options);
return Model.findAndCountAll(options).bind(this).then(function () {
expect(options).to.deep.equal(optionsClones);
});
});
});
});