Extend paging test
Tests page=0, POST and authentication
This commit is contained in:
parent
68aa854477
commit
ee61ccfd94
@ -230,24 +230,66 @@ function(done){
|
|||||||
|
|
||||||
// Test page and rows_per_page params
|
// Test page and rows_per_page params
|
||||||
test("paging", function(done){
|
test("paging", function(done){
|
||||||
assert.response(app, {
|
var sql = 'SELECT * FROM (VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9)) t(v)';
|
||||||
url: '/api/v1/sql?' + querystring.stringify({
|
var pr = [ [2,3], [0,4] ]; // page and rows
|
||||||
// note: select casing intentionally mixed
|
var methods = [ 'GET', 'POST' ];
|
||||||
q: 'SELECT * FROM (VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9)) t(v)',
|
var authorized = 0;
|
||||||
rows_per_page: 3,
|
var testing = 0;
|
||||||
page: 2
|
var method = 0;
|
||||||
}),
|
var testNext = function() {
|
||||||
headers: {host: 'vizzuality.cartodb.com'},
|
if ( testing >= pr.length ) {
|
||||||
method: 'GET'
|
if ( method+1 >= methods.length ) {
|
||||||
},{ }, function(res) {
|
if ( authorized ) {
|
||||||
|
done();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
authorized = 1;
|
||||||
|
method = 0;
|
||||||
|
testing = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
testing = 0;
|
||||||
|
++method;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var prcur = pr[testing++];
|
||||||
|
console.log("Test " + testing + "/" + pr.length
|
||||||
|
+ " method " + methods[method] + " "
|
||||||
|
+ ( authorized ? "authenticated" : "" ) );
|
||||||
|
var page = prcur[0];
|
||||||
|
var nrows = prcur[1];
|
||||||
|
var data_obj = {
|
||||||
|
q: sql,
|
||||||
|
rows_per_page: nrows,
|
||||||
|
page: page
|
||||||
|
};
|
||||||
|
if ( authorized ) data_obj['api_key'] = '1234';
|
||||||
|
var data = querystring.stringify(data_obj);
|
||||||
|
var req = {
|
||||||
|
url: '/api/v1/sql',
|
||||||
|
headers: {host: 'vizzuality.cartodb.com'}
|
||||||
|
};
|
||||||
|
if ( methods[method] == 'GET' ) {
|
||||||
|
req.method = 'GET';
|
||||||
|
req.url += '?' + data;
|
||||||
|
} else {
|
||||||
|
req.method = 'POST';
|
||||||
|
req.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||||
|
req.data = data;
|
||||||
|
}
|
||||||
|
assert.response(app, req, {}, function(res) {
|
||||||
assert.equal(res.statusCode, 200, res.body);
|
assert.equal(res.statusCode, 200, res.body);
|
||||||
var parsed = JSON.parse(res.body);
|
var parsed = JSON.parse(res.body);
|
||||||
assert.equal(parsed.rows.length, 3);
|
assert.equal(parsed.rows.length, nrows);
|
||||||
assert.equal(parsed.rows[0].v, 7);
|
for (var i=0; i<nrows; ++i) {
|
||||||
assert.equal(parsed.rows[1].v, 8);
|
var obt = parsed.rows[i].v;
|
||||||
assert.equal(parsed.rows[2].v, 9);
|
var exp = page * nrows + i + 1;
|
||||||
done();
|
assert.equal(obt, exp, "Value " + i + " in page " + page + " is " + obt + ", expected " + exp);
|
||||||
|
}
|
||||||
|
testNext();
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
testNext();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('POST /api/v1/sql with SQL parameter on SELECT only. no database param, just id using headers', function(done){
|
test('POST /api/v1/sql with SQL parameter on SELECT only. no database param, just id using headers', function(done){
|
||||||
|
Loading…
Reference in New Issue
Block a user