2015-08-04 21:53:50 +08:00
|
|
|
require('../helper');
|
|
|
|
|
|
|
|
var assert = require('../support/assert');
|
|
|
|
var qs = require('querystring');
|
|
|
|
var request = require('request');
|
|
|
|
|
|
|
|
describe('transaction', function() {
|
|
|
|
|
|
|
|
var SERVER_PORT = 5554;
|
|
|
|
|
|
|
|
var server;
|
2015-08-04 22:23:36 +08:00
|
|
|
before(function(done) {
|
2015-12-04 01:33:17 +08:00
|
|
|
server = require(global.settings.app_root + '/app/app')();
|
2015-08-04 21:53:50 +08:00
|
|
|
server.listen(SERVER_PORT, '127.0.0.1', done);
|
|
|
|
});
|
|
|
|
|
2015-08-04 22:23:36 +08:00
|
|
|
after(function(done) {
|
2015-08-04 21:53:50 +08:00
|
|
|
server.close(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
var sqlRequest = request.defaults({
|
|
|
|
headers: { host: 'vizzuality.localhost' }
|
|
|
|
});
|
|
|
|
|
2015-08-04 22:23:36 +08:00
|
|
|
function requestUrl(query) {
|
2015-08-04 21:53:50 +08:00
|
|
|
return 'http://127.0.0.1:' + SERVER_PORT + '/api/v1/sql?' + qs.stringify({ q: query });
|
|
|
|
}
|
|
|
|
|
|
|
|
var errorQuery = 'BEGIN; PREPARE _pstm AS select error; EXECUTE _pstm; COMMIT;';
|
|
|
|
|
2015-08-04 22:23:36 +08:00
|
|
|
it('should NOT fail to second request after error in transaction', function(done) {
|
|
|
|
sqlRequest(requestUrl(errorQuery), function(err, response, body) {
|
|
|
|
assert.ok(!err);
|
|
|
|
assert.equal(response.statusCode, 400);
|
|
|
|
|
|
|
|
var parsedBody = JSON.parse(body);
|
|
|
|
assert.ok(parsedBody);
|
|
|
|
assert.deepEqual(parsedBody, { error: ['column "error" does not exist'] });
|
2015-08-04 21:53:50 +08:00
|
|
|
|
2015-08-04 22:23:36 +08:00
|
|
|
sqlRequest(requestUrl('select 1 as foo'), function (err, response, body) {
|
2015-08-04 21:53:50 +08:00
|
|
|
assert.ok(!err);
|
2015-08-04 22:23:36 +08:00
|
|
|
assert.equal(response.statusCode, 200);
|
2015-08-04 21:53:50 +08:00
|
|
|
|
|
|
|
var parsedBody = JSON.parse(body);
|
|
|
|
assert.ok(parsedBody);
|
2015-08-04 22:23:36 +08:00
|
|
|
assert.deepEqual(parsedBody.rows, [{ foo: 1 }]);
|
2015-08-04 21:53:50 +08:00
|
|
|
|
2015-08-04 22:23:36 +08:00
|
|
|
done();
|
2015-08-04 21:53:50 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|