replace bigint unit test by integration tests

This commit is contained in:
Cyprien Autexier 2016-05-29 18:16:32 +02:00
parent b7231ebb2a
commit 0e693dfdca
4 changed files with 74 additions and 64 deletions

View File

@ -19,7 +19,6 @@ 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')

View File

@ -0,0 +1,73 @@
/*global describe, it, expect, testPromise*/
'use strict';
var Promise = testPromise;
module.exports = function (knex) {
var bigintTimestamp = 1464294366973;
var negativeBigintTimestamp = -1464294366973;
var unsafeBigint = 99071992547409911;
var negativeUnsafeBigint = -99071992547409911;
it('#test number mssql should not allow unsafe bigint', function () {
if (!/mssql/i.test(knex.client.dialect)) {
return Promise.resolve();
}
var constraintName = 'pk_id';
var tableName = 'bigint_test';
return knex.transaction(function (tr) {
return tr.schema.dropTableIfExists(tableName)
.then(function () {
return tr.schema.createTable(tableName, function (table) {
table.string('id').primary(constraintName);
table.bigInteger('expiry');
});
});
}).then(function () {
return knex(tableName).where('expiry', unsafeBigint).select("*");
}).map(function (row) {
// triggers request execution
}).then(function () {
return knex(tableName).where('expiry', negativeUnsafeBigint).select("*");
}).map(function (row) {
// triggers request execution
}).catch(function (err) {
expect(err).to.be.an.instanceof(Error);
expect(err.message).to.contain('Bigint must be safe integer or must be passed as string');
});
});
it('#test number mssql should allow safe bigint', function () {
if (!/mssql/i.test(knex.client.dialect)) {
return Promise.resolve();
}
var constraintName = 'pk_id';
var tableName = 'bigint_test';
return knex.transaction(function (tr) {
return tr.schema.dropTableIfExists(tableName)
.then(function () {
return tr.schema.createTable(tableName, function (table) {
table.string('id').primary(constraintName);
table.bigInteger('expiry');
});
});
}).then(function () {
return knex(tableName).insert({id : "positive", expiry: bigintTimestamp});
}).then(function () {
return knex(tableName).insert({id : "negative", expiry: negativeBigintTimestamp});
}).then(function () {
return knex(tableName).where('expiry', bigintTimestamp).select("*");
}).map(function (row) {
console.log(row);
expect(row.id).to.equal('positive');
}).then(function () {
return knex(tableName).where('expiry', negativeBigintTimestamp).select("*");
}).map(function (row) {
console.log(row);
expect(row.id).to.equal('negative');
}).catch(function (err) {
expect(err).to.be.undefined;
});
});
};

View File

@ -22,6 +22,7 @@ module.exports = function(knex) {
require('./builder/transaction')(knex);
require('./builder/deletes')(knex);
require('./builder/additional')(knex);
require('./datatype/bigint')(knex);
describe('knex.destroy', function() {
it('should allow destroying the pool with knex.destroy', function() {

View File

@ -1,63 +0,0 @@
/*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);
});
});