2015-12-07 16:40:51 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Requires the database and tables setup in config/environments/test.js to exist
|
|
|
|
* Ensure the user is present in the pgbouncer auth file too
|
|
|
|
* TODO: Add OAuth tests.
|
|
|
|
*
|
|
|
|
* To run this test, ensure that cartodb_test_user_1_db metadata exists
|
|
|
|
* in Redis for the vizzuality.cartodb.com domain
|
|
|
|
*
|
|
|
|
* SELECT 5
|
|
|
|
* HSET rails:users:vizzuality id 1
|
|
|
|
* HSET rails:users:vizzuality database_name cartodb_test_user_1_db
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
require('../helper');
|
|
|
|
|
|
|
|
var app = require(global.settings.app_root + '/app/app')();
|
|
|
|
var assert = require('../support/assert');
|
2015-12-07 18:29:55 +08:00
|
|
|
var querystring = require('querystring');
|
2015-12-07 16:40:51 +08:00
|
|
|
|
2015-12-22 02:57:10 +08:00
|
|
|
describe('job', function() {
|
2015-12-22 18:45:25 +08:00
|
|
|
var job = {};
|
2015-12-07 16:40:51 +08:00
|
|
|
|
2015-12-22 02:57:10 +08:00
|
|
|
it('POST /api/v2/job', function (done){
|
2015-12-07 16:40:51 +08:00
|
|
|
assert.response(app, {
|
2015-12-24 00:29:11 +08:00
|
|
|
url: '/api/v2/job?api_key=1234',
|
2015-12-22 02:57:10 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
|
|
|
query: "SELECT * FROM untitle_table_4"
|
|
|
|
})
|
2015-12-07 16:40:51 +08:00
|
|
|
}, {
|
2015-12-22 02:57:10 +08:00
|
|
|
status: 200
|
2015-12-07 16:40:51 +08:00
|
|
|
}, function(res) {
|
2015-12-22 18:45:25 +08:00
|
|
|
job = JSON.parse(res.body);
|
2015-12-07 16:40:51 +08:00
|
|
|
assert.deepEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
2015-12-22 02:57:10 +08:00
|
|
|
assert.equal(job.query, "SELECT * FROM untitle_table_4");
|
|
|
|
assert.equal(job.status, "pending");
|
|
|
|
assert.equal(job.user, "vizzuality");
|
2015-12-07 16:40:51 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-12-24 00:29:11 +08:00
|
|
|
it('GET /api/v2/job/:job_id', function (done){
|
2015-12-22 18:45:25 +08:00
|
|
|
assert.response(app, {
|
2015-12-24 00:29:11 +08:00
|
|
|
url: '/api/v2/job/' + job.job_id + '?api_key=1234',
|
2015-12-22 18:45:25 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function(res) {
|
|
|
|
var jobGot = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
|
|
|
assert.equal(jobGot.query, "SELECT * FROM untitle_table_4");
|
|
|
|
assert.equal(jobGot.status, "pending");
|
|
|
|
assert.equal(jobGot.user, "vizzuality");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-12-07 16:40:51 +08:00
|
|
|
});
|