is-soft-deleted.test.js
1.9 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
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require(__dirname + '/../support'),
current = Support.sequelize,
DataTypes = require(__dirname + '/../../../lib/data-types'),
Sequelize = Support.Sequelize,
moment = require('moment');
describe(Support.getTestDialectTeaser('Instance'), () => {
describe('isSoftDeleted', () => {
beforeEach(function() {
const User = current.define('User', {
name: DataTypes.STRING,
birthdate: DataTypes.DATE,
meta: DataTypes.JSON,
deletedAt: {
type: Sequelize.DATE
}
});
const ParanoidUser = current.define('User', {
name: DataTypes.STRING,
birthdate: DataTypes.DATE,
meta: DataTypes.JSON,
deletedAt: {
type: Sequelize.DATE
}
}, {
paranoid: true
});
this.paranoidUser = ParanoidUser.build({
name: 'a'
}, {
isNewRecord: false,
raw: true
});
this.user = User.build({
name: 'a'
}, {
isNewRecord: false,
raw: true
});
});
it('should not throw if paranoid is set to true', function() {
expect(() => {
this.paranoidUser.isSoftDeleted();
}).to.not.throw();
});
it('should throw if paranoid is set to false', function() {
expect(() => {
this.user.isSoftDeleted();
}).to.throw('Model is not paranoid');
});
it('should return false if the soft-delete property is the same as the default value', function() {
this.paranoidUser.setDataValue('deletedAt', null);
expect(this.paranoidUser.isSoftDeleted()).to.be.false;
});
it('should return true if the soft-delete property is set', function() {
this.paranoidUser.setDataValue('deletedAt', moment().subtract(5, 'days').format());
expect(this.paranoidUser.isSoftDeleted()).to.be.true;
});
});
});