mirror of
https://github.com/knex/knex.git
synced 2025-12-28 15:38:41 +00:00
Add unit tests for mssql bigints (to be fixed)
This commit is contained in:
parent
5f5aff114e
commit
b7231ebb2a
@ -19,6 +19,7 @@ Promise.longStackTraces();
|
||||
|
||||
describe('Query Building Tests', function() {
|
||||
require('./unit/query/builder')
|
||||
require('./unit/client/client')
|
||||
require('./unit/schema/mysql')('mysql')
|
||||
require('./unit/schema/mysql')('maria')
|
||||
require('./unit/schema/mysql')('mysql2')
|
||||
|
||||
63
test/unit/client/client.js
Normal file
63
test/unit/client/client.js
Normal file
@ -0,0 +1,63 @@
|
||||
/*global expect, describe, it*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var Promise = global.testPromise = require('../../../lib/promise')
|
||||
var MSSQL_Client = require('../../../lib/dialects/mssql')
|
||||
|
||||
var clients = {
|
||||
mssql: new MSSQL_Client({})
|
||||
}
|
||||
|
||||
|
||||
describe("Client", function () {
|
||||
|
||||
var reqMock = {
|
||||
input: sinon.stub().returns(true),
|
||||
query: sinon.stub().returns(Promise.resolve(true))
|
||||
};
|
||||
var connectionMock = {
|
||||
request : sinon.stub().returns(reqMock)
|
||||
};
|
||||
|
||||
|
||||
|
||||
it("mssql should allow safe bigint ", function (done) {
|
||||
var bigintTimestamp = 1464294366973;
|
||||
var negativeBigintTimestamp = -1464294366973;
|
||||
clients.mssql.query(connectionMock, clients.mssql.queryBuilder().select('*').from('users').where('expiry', bigintTimestamp).toQuery())
|
||||
.catch(function(error){
|
||||
expect(error).to.be.undefined
|
||||
})
|
||||
.then(function(){
|
||||
return clients.mssql.query(connectionMock, clients.mssql.queryBuilder().select('*').from('users').where('expiry', negativeBigintTimestamp).toQuery())
|
||||
})
|
||||
.catch(function(error){
|
||||
expect(error).to.be.undefined
|
||||
})
|
||||
.then(function(res){
|
||||
expect(res).to.be.true;
|
||||
})
|
||||
.finally(done);
|
||||
});
|
||||
|
||||
it("mssql should not allow unsafe bigint ", function (done) {
|
||||
var unsafeBigint = 99071992547409911;
|
||||
var negativeUnsafeBigint = -99071992547409911;
|
||||
clients.mssql.query(connectionMock, clients.mssql.queryBuilder().select('*').from('users').where('expiry', unsafeBigint).toQuery())
|
||||
.catch(function(error){
|
||||
expect(error).to.be.an('Error');
|
||||
expect(error.message).to.contain('Bigint must be safe integer or must be passed as string');
|
||||
expect(reqMock.query.callCount).to.equal(1);
|
||||
})
|
||||
.then(function(){
|
||||
return clients.mssql.query(connectionMock, clients.mssql.queryBuilder().select('*').from('users').where('expiry', negativeUnsafeBigint).toQuery())
|
||||
})
|
||||
.catch(function(error){
|
||||
expect(error).to.be.an('Error');
|
||||
expect(error.message).to.contain('Bigint must be safe integer or must be passed as string');
|
||||
expect(reqMock.query.callCount).to.equal(1);
|
||||
})
|
||||
.finally(done);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user