forked from sequelize/sequelize
/
find-by-pk.test.js
42 lines (36 loc) · 1.09 KB
/
find-by-pk.test.js
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
'use strict';
const chai = require('chai');
const expect = chai.expect;
const Support = require('../support');
const Sequelize = Support.Sequelize;
const Op = Sequelize.Op;
const current = Support.sequelize;
const sinon = require('sinon');
const DataTypes = require('../../../lib/data-types');
describe(Support.getTestDialectTeaser('Model'), () => {
describe('method findByPk', () => {
beforeEach(function () {
this.stub = sinon.stub(Sequelize.Model, 'findAll').resolves();
});
afterEach(() => {
sinon.restore();
});
it('should call internal findOne() method if findOne() is overridden', async () => {
const Model = current.define('model', {
unique1: {
type: DataTypes.INTEGER,
unique: 'unique',
},
unique2: {
type: DataTypes.INTEGER,
unique: 'unique',
},
});
Model.findOne = sinon.stub();
sinon.spy(Sequelize.Model, 'findOne');
await Model.findByPk(1);
Model.findOne.should.not.have.been.called;
Sequelize.Model.findOne.should.have.been.called;
});
});
});