CartoDB-SQL-API/test/acceptance/query-float-values.js
Raúl Marín df523960a2
Fix test timeouts (#612)
* Tests: Work with re-runs

* Test: Adapt copyfrom test
- Reduce timeout from 10 to 1 ms.
- Increase the size of the file from 6 to 2016 rows.

* Use node-cartodb-psql 0.14.0

Ref: https://github.com/CartoDB/CartoDB-SQL-API/pull/612
2019-09-13 11:28:37 +02:00

73 lines
2.5 KiB
JavaScript

'use strict';
require('../helper');
var server = require('../../app/server')();
var assert = require('../support/assert');
var querystring = require('querystring');
var step = require('step');
describe('special numeric (float) values', function() {
var RESPONSE_OK = {
statusCode: 200
};
var HEADERS = {
host: 'vizzuality.localhost.lan:8080'
};
var METHOD = 'GET';
var URL = '/api/v1/sql?api_key=1234&';
it('should cast Infinity and NaN values properly', function (done) {
step(
function createTable () {
var next = this;
var opts = {
url: URL + querystring.stringify({
q: 'drop table if exists numbers_test; create table numbers_test(val float)'
}),
headers: HEADERS,
method: METHOD
};
assert.response(server, opts, RESPONSE_OK, next);
},
function insertData (err) {
assert.ifError(err);
var next = this;
var opts = {
url: URL + querystring.stringify({
q: [
'insert into numbers_test',
' values (\'NaN\'::float), (\'infinity\'::float), (\'-infinity\'::float), (1::float)'
].join('')
}),
headers: HEADERS,
method: METHOD
};
assert.response(server, opts, RESPONSE_OK, next);
},
function queryData (err) {
assert.ifError(err);
var next = this;
var opts = {
url: URL + querystring.stringify({
q: 'select * from numbers_test'
}),
headers: HEADERS,
method: METHOD
};
assert.response(server, opts, RESPONSE_OK, next);
},
function assertResult (err, res) {
assert.ifError(err);
var result = JSON.parse(res.body);
assert.ok(Array.isArray(result.rows));
assert.equal(result.rows[0].val, 'NaN');
assert.equal(result.rows[1].val, 'Infinity');
assert.equal(result.rows[2].val, '-Infinity');
assert.equal(result.rows[3].val, 1);
done();
}
);
});
});