regressions.test.js
2.28 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
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require(__dirname + '/../../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', 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'
});
return this.sequelize.sync({ force: true })
.then(() => User.bulkCreate([
{ UserName: 'Vayom' },
{ UserName: 'Shaktimaan' },
{ UserName: 'Nikita' },
{ UserName: 'Aryamaan' }
], { returning: true }))
.spread((vyom, shakti, nikita, arya) => {
return Sequelize.Promise.all([
vyom.createLoginLog(),
shakti.createLoginLog(),
nikita.createLoginLog(),
arya.createLoginLog()
]);
}).then(() => {
return LoginLog.findAll({
include: [
{
model: User,
where: {
UserName: {
[Op.like]: '%maan%'
}
}
}
],
order: [[User, 'UserName', 'DESC']],
offset: 0,
limit: 10
});
}).then(logs => {
expect(logs).to.have.length(2);
expect(logs[0].User.get('UserName')).to.equal('Shaktimaan');
expect(logs[1].User.get('UserName')).to.equal('Aryamaan');
});
});
});
}