forked from sequelize/sequelize
/
decrement.test.js
52 lines (43 loc) · 1.37 KB
/
decrement.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
43
44
45
46
47
48
49
50
51
52
'use strict';
const chai = require('chai');
const expect = chai.expect;
const Support = require('../../support');
const current = Support.sequelize;
const { DataTypes } = require('@sequelize/core');
const sinon = require('sinon');
describe(Support.getTestDialectTeaser('Instance'), () => {
describe('decrement', () => {
it('is not allowed if the instance does not have a primary key defined', async () => {
const User = current.define('User', {});
const instance = User.build({});
await expect(instance.decrement()).to.be.rejectedWith('but this model instance is missing the value of its primary key');
});
describe('options tests', () => {
let stub; let instance;
const Model = current.define('User', {
id: {
type: DataTypes.BIGINT,
primaryKey: true,
autoIncrement: true,
},
});
before(() => {
stub = sinon.stub(current, 'queryRaw').resolves(
{
_previousDataValues: { id: 3 },
dataValues: { id: 1 },
},
);
});
after(() => {
stub.restore();
});
it('should allow decrements even if options are not given', () => {
instance = Model.build({ id: 3 }, { isNewRecord: false });
expect(() => {
instance.decrement(['id']);
}).to.not.throw();
});
});
});
});