不要怂,就是干,撸起袖子干!

Commit 39c512b1 by Mick Hansen

add tests for order validation

1 parent c03a18e2
...@@ -1272,7 +1272,13 @@ module.exports = (function() { ...@@ -1272,7 +1272,13 @@ module.exports = (function() {
if (Array.isArray(options.order)) { if (Array.isArray(options.order)) {
options.order.forEach(function(t) { options.order.forEach(function(t) {
if (Array.isArray(t) && _.size(t) > 1) { if (Array.isArray(t) && _.size(t) > 1) {
validateOrder(_.last(t)); if (t[0] instanceof Model || t[0].model instanceof Model) {
if (typeof t[t.length - 2] === "string") {
validateOrder(_.last(t));
}
} else {
validateOrder(_.last(t));
}
} }
if (subQuery && (Array.isArray(t) && !(t[0] instanceof Model) && !(t[0].model instanceof Model))) { if (subQuery && (Array.isArray(t) && !(t[0] instanceof Model) && !(t[0].model instanceof Model))) {
......
...@@ -525,7 +525,7 @@ describe(Support.getTestDialectTeaser('Include'), function() { ...@@ -525,7 +525,7 @@ describe(Support.getTestDialectTeaser('Include'), function() {
], ],
order: [ order: [
User.rawAttributes.id, User.rawAttributes.id,
[Product, 'id', 'ASC'] [Product, 'id']
] ]
}).done(function(err, user) { }).done(function(err, user) {
expect(err).not.to.be.ok; expect(err).not.to.be.ok;
......
...@@ -69,6 +69,45 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -69,6 +69,45 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
} }
}); });
describe.only('injections', function () {
beforeEach(function () {
this.User = this.sequelize.define('user', {
});
this.Group = this.sequelize.define('group', {
});
this.User.belongsTo(this.Group);
return this.sequelize.sync({force: true});
});
it('should throw when 2nd order argument is not ASC or DESC', function () {
return expect(this.User.findAll({
order: [
['id', ';DELETE YOLO INJECTIONS']
]
})).to.eventually.be.rejectedWith(Error, 'Order must be \'ASC\' or \'DESC\', \';DELETE YOLO INJECTIONS\' given');
});
it('should throw with include when last order argument is not ASC or DESC', function () {
return expect(this.User.findAll({
include: [this.Group],
order: [
[this.Group, 'id', ';DELETE YOLO INJECTIONS']
]
})).to.eventually.be.rejectedWith(Error, 'Order must be \'ASC\' or \'DESC\', \';DELETE YOLO INJECTIONS\' given');
});
it('should not throw with include when last order argument is a field', function () {
return this.User.findAll({
include: [this.Group],
order: [
[this.Group, 'id']
]
});
});
});
}); });
}); });
}); });
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!