Skip to content
Permalink
Browse files

test: add integration tests for #3485

  • Loading branch information
edvardchen
edvardchen committed Oct 28, 2019
1 parent ef124fa commit 7f7a82b658bb4fa7395a163c9ca30baeaccf9cb1
Showing with 36 additions and 0 deletions.
  1. +36 −0 test/integration/builder/selects.js
@@ -1,6 +1,7 @@
/*global expect, d*/
'use strict';

const mysqlErrors = require('mysql/lib/protocol/constants/errors');
const _ = require('lodash');
const assert = require('assert');
const Runner = require('../../../lib/runner');
@@ -1380,5 +1381,40 @@ module.exports = function(knex) {
}
}
});

it('select from subquery', async function() {
const subquery = knex.from('accounts').whereBetween('id', [3, 5]);
return knex
.pluck('id')
.orderBy('id')
.from(subquery)
.then(
(rows) => {
expect(rows).to.deep.equal([3, 4, 5]);
expect(knex.client.driverName).to.oneOf(['sqlite3', 'oracledb']);
},
(e) => {
switch (knex.client.driverName) {
case 'mysql':
case 'mysql2':
expect(e.errno).to.equal(
mysqlErrors.ER_DERIVED_MUST_HAVE_ALIAS
);
break;
case 'pg':
expect(e.message).to.contain('must have an alias');
break;

case 'mssql':
expect(e.message).to.contain(
"Incorrect syntax near the keyword 'order'"
);
break;
default:
throw e;
}
}
);
});
});
};

0 comments on commit 7f7a82b

Please sign in to comment.
You can’t perform that action at this time.