order.test.js
2.33 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
'use strict';
var chai = require('chai')
, Sequelize = require('../../../index')
, expect = chai.expect
, Support = require(__dirname + '/../../support')
, DataTypes = require(__dirname + '/../../../lib/data-types')
, dialect = Support.getTestDialect()
, config = require(__dirname + '/../../config/config')
, datetime = require('chai-datetime')
, _ = require('lodash')
, moment = require('moment')
, async = require('async')
, current = Support.sequelize;
chai.use(datetime);
chai.config.includeStack = true;
describe(Support.getTestDialectTeaser('Model'), function() {
describe('findAll', function () {
describe('order', function () {
describe('Sequelize.literal()', function () {
beforeEach(function () {
this.User = this.sequelize.define('User', {
email: DataTypes.STRING
});
return this.User.sync({force: true}).bind(this).then(function () {
return this.User.create({
email: 'test@sequelizejs.com'
});
});
});
it('should work with order: literal()', function () {
return this.User.findAll({
order: this.sequelize.literal("email = "+this.sequelize.escape('test@sequelizejs.com'))
}).then(function (users) {
expect(users.length).to.equal(1);
users.forEach(function (user) {
expect(user.get('email')).to.be.ok;
});
});
});
it('should work with order: [literal()]', function () {
return this.User.findAll({
order: [this.sequelize.literal("email = "+this.sequelize.escape('test@sequelizejs.com'))]
}).then(function (users) {
expect(users.length).to.equal(1);
users.forEach(function (user) {
expect(user.get('email')).to.be.ok;
});
});
});
it('should work with order: [[literal()]]', function () {
return this.User.findAll({
order: [
[this.sequelize.literal("email = "+this.sequelize.escape('test@sequelizejs.com'))]
]
}).then(function (users) {
expect(users.length).to.equal(1);
users.forEach(function (user) {
expect(user.get('email')).to.be.ok;
});
});
});
});
});
});
});