regressions.test.js
3.92 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require('../../support'),
Sequelize = Support.Sequelize,
Op = Sequelize.Op,
dialect = Support.getTestDialect();
if (dialect.match(/^mssql/)) {
describe('[MSSQL Specific] Regressions', () => {
it('does not duplicate columns in ORDER BY statement, #9008', async function() {
const LoginLog = this.sequelize.define('LoginLog', {
ID: {
field: 'id',
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
UserID: {
field: 'userid',
type: Sequelize.UUID,
allowNull: false
}
});
const User = this.sequelize.define('User', {
UserID: {
field: 'userid',
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
primaryKey: true
},
UserName: {
field: 'username',
type: Sequelize.STRING(50),
allowNull: false
}
});
LoginLog.belongsTo(User, {
foreignKey: 'UserID'
});
User.hasMany(LoginLog, {
foreignKey: 'UserID'
});
await this.sequelize.sync({ force: true });
const [vyom, shakti, nikita, arya] = await User.bulkCreate([
{ UserName: 'Vayom' },
{ UserName: 'Shaktimaan' },
{ UserName: 'Nikita' },
{ UserName: 'Aryamaan' }
], { returning: true });
await Promise.all([
vyom.createLoginLog(),
shakti.createLoginLog(),
nikita.createLoginLog(),
arya.createLoginLog()
]);
const logs = await LoginLog.findAll({
include: [
{
model: User,
where: {
UserName: {
[Op.like]: '%maan%'
}
}
}
],
order: [[User, 'UserName', 'DESC']],
offset: 0,
limit: 10
});
expect(logs).to.have.length(2);
expect(logs[0].User.get('UserName')).to.equal('Shaktimaan');
expect(logs[1].User.get('UserName')).to.equal('Aryamaan');
});
});
it('sets the varchar(max) length correctly on describeTable', async function() {
const Users = this.sequelize.define('_Users', {
username: Sequelize.STRING('MAX')
}, { freezeTableName: true });
await Users.sync({ force: true });
const metadata = await this.sequelize.getQueryInterface().describeTable('_Users');
const username = metadata.username;
expect(username.type).to.include('(MAX)');
});
it('sets the char(10) length correctly on describeTable', async function() {
const Users = this.sequelize.define('_Users', {
username: Sequelize.CHAR(10)
}, { freezeTableName: true });
await Users.sync({ force: true });
const metadata = await this.sequelize.getQueryInterface().describeTable('_Users');
const username = metadata.username;
expect(username.type).to.include('(10)');
});
it('saves value bigger than 2147483647, #11245', async function() {
const BigIntTable = this.sequelize.define('BigIntTable', {
business_id: {
type: Sequelize.BIGINT,
allowNull: false
}
}, {
freezeTableName: true
});
const bigIntValue = 2147483648;
await BigIntTable.sync({ force: true });
await BigIntTable.create({
business_id: bigIntValue
});
const record = await BigIntTable.findOne();
expect(Number(record.business_id)).to.equals(bigIntValue);
});
it('saves boolean is true, #12090', async function() {
const BooleanTable = this.sequelize.define('BooleanTable', {
status: {
type: Sequelize.BOOLEAN,
allowNull: false
}
}, {
freezeTableName: true
});
const value = true;
await BooleanTable.sync({ force: true });
await BooleanTable.create({
status: value
});
const record = await BooleanTable.findOne();
expect(record.status).to.equals(value);
});
}