From fc307718796193f24b9c781bb8962f41e9ed61db Mon Sep 17 00:00:00 2001 From: Francisco Dans Date: Mon, 1 Jun 2015 15:16:05 +0200 Subject: [PATCH] adds couple more tests --- test/acceptance/export/spatialite.js | 45 +++++++++++++++++++++------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/test/acceptance/export/spatialite.js b/test/acceptance/export/spatialite.js index 18138e6d..d75f3c56 100644 --- a/test/acceptance/export/spatialite.js +++ b/test/acceptance/export/spatialite.js @@ -3,25 +3,50 @@ var assert = require('../../support/assert'); var sqlite = require('sqlite3'); describe.only('spatialite query',function(){ - var serverResponse; - before(function(done){ + it('returns a valid sqlite database', function(done){ assert.response(app, { url: '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4%20LIMIT%201&format=spatialite', headers: {host: 'vizzuality.cartodb.com'}, method: 'GET' },{ }, function(res) { - serverResponse = res; + assert.equal(res.statusCode, 200, res.body); + assert.equal(res.headers["content-type"], "application/x-sqlite3; charset=utf-8"); + var db = new sqlite.Database(res.body); + var qr = db.get("PRAGMA database_list", function(err){ + assert.equal(err, null); + done(); + }); + assert.notEqual(qr, undefined); + }); + + }); + + it('different file name', function(done){ + assert.response(app, { + url: '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4%20LIMIT%201&format=spatialite&filename=manolo', + headers: {host: 'vizzuality.cartodb.com'}, + method: 'GET' + },{ }, function(res) { + assert.equal(res.headers["content-type"], "application/x-sqlite3; charset=utf-8"); + assert.notEqual(res.headers["content-disposition"].indexOf("manolo.sqlite"), -1); done(); }); }); - it('returns a valid sqlite database', function(done){ - assert.equal(serverResponse.statusCode, 200, serverResponse.body); - var db = new sqlite.Database(serverResponse.body); - var qr = db.get("PRAGMA database_list", function(err, result){ - assert.equal(err, null); - done(); + + it('gets database schema', function(done){ + assert.response(app, { + url: '/api/v1/sql?q=SELECT%20*%20FROM%20untitle_table_4%20LIMIT%201&format=spatialite', + headers: {host: 'vizzuality.cartodb.com'}, + method: 'GET' + },{ }, function(res) { + var db = new sqlite.Database(res.body); + var schemaQuery = "SELECT name, sql FROM sqlite_master WHERE type='table' ORDER BY name"; + var qr = db.get(schemaQuery, function(err){ + assert.equal(err, null); + done(); + }); + assert.notEqual(qr, undefined); }); - assert.notEqual(qr, undefined); }); });