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');
|
2016-01-12 17:06:31 +08:00
|
|
|
var metadataBackend = require('cartodb-redis')({
|
|
|
|
host: global.settings.redis_host,
|
|
|
|
port: global.settings.redis_port,
|
|
|
|
max: global.settings.redisPool,
|
|
|
|
idleTimeoutMillis: global.settings.redisIdleTimeoutMillis,
|
|
|
|
reapIntervalMillis: global.settings.redisReapIntervalMillis
|
|
|
|
});
|
2015-12-07 16:40:51 +08:00
|
|
|
|
2015-12-29 22:46:04 +08:00
|
|
|
describe('job module', function() {
|
2015-12-22 18:45:25 +08:00
|
|
|
var job = {};
|
2015-12-07 16:40:51 +08:00
|
|
|
|
2016-01-12 17:06:31 +08:00
|
|
|
after(function (done) {
|
2016-01-12 17:08:56 +08:00
|
|
|
// batch services is not activate, so we need empty the queue to avoid unexpected
|
|
|
|
// behaviour fot further test
|
2016-01-12 17:06:31 +08:00
|
|
|
metadataBackend.redisCmd(5, 'DEL', [ 'batch:queues:localhost' ], done);
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('POST /api/v2/sql/job should respond with 200 and the created job', function (done){
|
2015-12-07 16:40:51 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/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
|
|
|
}, {
|
2016-01-07 19:06:01 +08:00
|
|
|
status: 201
|
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-29 22:46:04 +08:00
|
|
|
assert.ok(job.job_id);
|
2015-12-22 02:57:10 +08:00
|
|
|
assert.equal(job.query, "SELECT * FROM untitle_table_4");
|
|
|
|
assert.equal(job.user, "vizzuality");
|
2015-12-07 16:40:51 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('POST /api/v2/sql/job without query should respond with 400 and the corresponding message of error',
|
|
|
|
function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({})
|
|
|
|
}, {
|
|
|
|
status: 400
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, { error: [ 'You must indicate a sql query' ] });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('POST /api/v2/sql/job with bad query param should respond with 400 and message of error', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
|
|
|
q: "SELECT * FROM untitle_table_4"
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 400
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, { error: [ 'You must indicate a sql query' ] });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('POST /api/v2/sql/job with wrong api key should respond with 401 permission denied', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=wrong',
|
2016-01-06 00:42:28 +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"
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 401
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, { error: [ 'permission denied' ] });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('POST /api/v2/sql/job with wrong host header should respond with 404 not found', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=wrong',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'wrong-host.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'POST',
|
|
|
|
data: querystring.stringify({
|
|
|
|
query: "SELECT * FROM untitle_table_4"
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 404
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, {
|
|
|
|
error: [
|
|
|
|
'Sorry, we can\'t find CartoDB user \'wrong-host\'. ' +
|
|
|
|
'Please check that you have entered the correct domain.'
|
|
|
|
]
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('GET /api/v2/sql/job/:job_id should respond with 200 and the requested job', function (done){
|
2015-12-22 18:45:25 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/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.user, "vizzuality");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('GET /api/v2/sql/job/:job_id with wrong api key should respond with 401 permission denied', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=wrong',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 401
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, { error: [ 'permission denied' ] });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('GET /api/v2/sql/job/ with wrong host header respond with 404 not found', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'wrong-host.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 404
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error , {
|
|
|
|
error: [
|
|
|
|
'Sorry, we can\'t find CartoDB user \'wrong-host\'. ' +
|
|
|
|
'Please check that you have entered the correct domain.'
|
|
|
|
]
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('PUT /api/v2/sql/job/:job_id should respond 200 and the updated job', function (done) {
|
2016-01-06 00:42:28 +08:00
|
|
|
var query ="SELECT cartodb_id FROM untitle_table_4";
|
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=1234',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'PUT',
|
|
|
|
data: querystring.stringify({
|
|
|
|
query: query
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function(res) {
|
2016-01-12 03:14:15 +08:00
|
|
|
var updatedJob = JSON.parse(res.body);
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.deepEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
2016-01-12 03:14:15 +08:00
|
|
|
assert.equal(updatedJob.job_id, job.job_id);
|
|
|
|
assert.equal(updatedJob.query, query);
|
|
|
|
assert.equal(updatedJob.user, "vizzuality");
|
2016-01-06 00:42:28 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('PUT /api/v2/sql/job/:job_id without query should respond with 400 and message of error', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=1234',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'PUT',
|
|
|
|
data: querystring.stringify({})
|
|
|
|
}, {
|
|
|
|
status: 400
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, { error: [ 'You must indicate a sql query' ] });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('PUT /api/v2/sql/job with bad query param should respond with 400 and message of error', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=1234',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'PUT',
|
|
|
|
data: querystring.stringify({
|
|
|
|
q: "SELECT * FROM untitle_table_4"
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 400
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, { error: [ 'You must indicate a sql query' ] });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('PUT /api/v2/sql/job/:job_id with wrong api key should respond with 401 permission denied', function (done) {
|
2016-01-06 00:42:28 +08:00
|
|
|
var query ="SELECT cartodb_id FROM untitle_table_4";
|
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=wrong',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'PUT',
|
|
|
|
data: querystring.stringify({
|
|
|
|
query: query
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 401
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, { error: [ 'permission denied' ] });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('PUT /api/v2/sql/job with wrong host header should respond with 404 not found', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=wrong',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'wrong-host.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'PUT',
|
|
|
|
data: querystring.stringify({
|
|
|
|
query: "SELECT * FROM untitle_table_4"
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 404
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error , {
|
|
|
|
error: [
|
|
|
|
'Sorry, we can\'t find CartoDB user \'wrong-host\'. ' +
|
|
|
|
'Please check that you have entered the correct domain.'
|
|
|
|
]
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('PATCH /api/v2/sql/job/:job_id should respond 200 and the updated job', function (done) {
|
2016-01-06 00:42:28 +08:00
|
|
|
var query ="SELECT * FROM untitle_table_4";
|
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=1234',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'PATCH',
|
|
|
|
data: querystring.stringify({
|
|
|
|
query: query
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function(res) {
|
2016-01-12 03:14:15 +08:00
|
|
|
var updatedJob = JSON.parse(res.body);
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.deepEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
2016-01-12 03:14:15 +08:00
|
|
|
assert.equal(updatedJob.job_id, job.job_id);
|
|
|
|
assert.equal(updatedJob.query, query);
|
|
|
|
assert.equal(updatedJob.user, "vizzuality");
|
2016-01-06 00:42:28 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('PATCH /api/v2/sql/job/:job_id without query should respond with 400 and message of error', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=1234',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'PATCH',
|
|
|
|
data: querystring.stringify({})
|
|
|
|
}, {
|
|
|
|
status: 400
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, { error: [ 'You must indicate a sql query' ] });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('PATCH /api/v2/sql/job with bad query param should respond with 400 and message of error', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=1234',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'PATCH',
|
|
|
|
data: querystring.stringify({
|
|
|
|
q: "SELECT * FROM untitle_table_4"
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 400
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, { error: [ 'You must indicate a sql query' ] });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('PATCH /api/v2/sql/job/:job_id with wrong api key should respond with 401 permission denied', function (done) {
|
2016-01-06 00:42:28 +08:00
|
|
|
var query ="SELECT * FROM untitle_table_4";
|
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=wrong',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'PATCH',
|
|
|
|
data: querystring.stringify({
|
|
|
|
query: query
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 401
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, { error: [ 'permission denied' ] });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('PATCH /api/v2/sql/job with wrong host header should respond with 404 not found', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=wrong',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'wrong-host.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'PATCH',
|
|
|
|
data: querystring.stringify({
|
|
|
|
query: "SELECT * FROM untitle_table_4"
|
|
|
|
})
|
|
|
|
}, {
|
|
|
|
status: 404
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error , {
|
|
|
|
error: [
|
|
|
|
'Sorry, we can\'t find CartoDB user \'wrong-host\'. ' +
|
|
|
|
'Please check that you have entered the correct domain.'
|
|
|
|
]
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('GET /api/v2/sql/job/ should respond with 200 and a job\'s list', function (done){
|
2015-12-29 22:46:04 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
2015-12-29 22:46:04 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function(res) {
|
|
|
|
var jobs = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
|
|
|
assert.ok(jobs instanceof Array);
|
|
|
|
assert.ok(jobs.length > 0);
|
|
|
|
assert.ok(jobs[0].job_id);
|
|
|
|
assert.ok(jobs[0].status);
|
|
|
|
assert.ok(jobs[0].query);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-01-06 00:42:28 +08:00
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('GET /api/v2/sql/job/ with wrong api key should respond with 401 permission denied', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=wrong',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 401
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, { error: [ 'permission denied' ] });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('GET /api/v2/sql/job/ without host header respond with 404 not found', function (done){
|
2016-01-06 00:42:28 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job?api_key=1234',
|
2016-01-06 00:42:28 +08:00
|
|
|
headers: { 'host': 'wrong-host.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'GET'
|
|
|
|
}, {
|
|
|
|
status: 404
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error , {
|
|
|
|
error: [
|
|
|
|
'Sorry, we can\'t find CartoDB user \'wrong-host\'. ' +
|
|
|
|
'Please check that you have entered the correct domain.'
|
|
|
|
]
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2016-01-12 03:14:15 +08:00
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('DELETE /api/v2/sql/job/:job_id should respond with 200 and the requested job', function (done){
|
2016-01-12 03:14:15 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=1234',
|
2016-01-12 03:14:15 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'DELETE'
|
|
|
|
}, {
|
|
|
|
status: 200
|
|
|
|
}, function(res) {
|
|
|
|
var jobCancelled = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(res.headers['content-type'], 'application/json; charset=utf-8');
|
2016-01-12 17:06:31 +08:00
|
|
|
assert.equal(jobCancelled.job_id, job.job_id);
|
2016-01-12 03:14:15 +08:00
|
|
|
assert.equal(jobCancelled.query, "SELECT * FROM untitle_table_4");
|
|
|
|
assert.equal(jobCancelled.user, "vizzuality");
|
|
|
|
assert.equal(jobCancelled.status, "cancelled");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('DELETE /api/v2/sql/job/:job_id with wrong api key should respond with 401 permission denied', function (done){
|
2016-01-12 03:14:15 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=wrong',
|
2016-01-12 03:14:15 +08:00
|
|
|
headers: { 'host': 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'DELETE'
|
|
|
|
}, {
|
|
|
|
status: 401
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error, { error: [ 'permission denied' ] });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-19 03:12:44 +08:00
|
|
|
it('DELETE /api/v2/sql/job/ with wrong host header respond with 404 not found', function (done){
|
2016-01-12 03:14:15 +08:00
|
|
|
assert.response(app, {
|
2016-01-19 03:12:44 +08:00
|
|
|
url: '/api/v2/sql/job/' + job.job_id + '?api_key=1234',
|
2016-01-12 03:14:15 +08:00
|
|
|
headers: { 'host': 'wrong-host.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
method: 'DELETE'
|
|
|
|
}, {
|
|
|
|
status: 404
|
|
|
|
}, function(res) {
|
|
|
|
var error = JSON.parse(res.body);
|
|
|
|
assert.deepEqual(error , {
|
|
|
|
error: [
|
|
|
|
'Sorry, we can\'t find CartoDB user \'wrong-host\'. ' +
|
|
|
|
'Please check that you have entered the correct domain.'
|
|
|
|
]
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2015-12-07 16:40:51 +08:00
|
|
|
});
|