diff --git a/spec/smokes/configuration.js b/spec/smokes/configuration.js index 42ad967bb2..3853e94fc1 100644 --- a/spec/smokes/configuration.js +++ b/spec/smokes/configuration.js @@ -9,4 +9,3 @@ configuration.API_KEY = options['cartodb_api_key'] // API key configuration.USER_EMAIL = options['cartodb_user_email'] // email configuration.USER_PASSWORD = options['cartodb_user_password'] // password module.exports = configuration - diff --git a/spec/smokes/helpers/table.js b/spec/smokes/helpers/table.js new file mode 100644 index 0000000000..b82bd30144 --- /dev/null +++ b/spec/smokes/helpers/table.js @@ -0,0 +1,57 @@ +/* Table utilities using the table endpoint */ + +module.exports = { + + removeAllTables: function(api_key) { + this.api_key = api_key || configuration.API_KEY; + var url = configuration.BASE_URL + '/api/v1/tables'; + var headers = { + 'Host' : configuration.HOST, + 'Accept' : 'application/json' + }; + + casper.thenOpen(tools.auth(url)).then(function() { + response = JSON.parse(casper.getPageContent()); + for (table in response.tables) { + var table_id = response.tables[table]["id"]; + var url = configuration.BASE_URL + '/api/v1/tables/' + table_id; + casper.log("Removing table "+table_id); + casper.thenOpen(tools.auth(url), { + method: 'delete', + data: JSON.stringify(payload), + headers: headers + }); + }; + }) + }, + + + Table: function(tableName, api_key) { + //Creates a random table name with the timestamp + this.tableName = tableName || "test" + Date.now(); + this.api_key = api_key || configuration.API_KEY; + + + this.create = function() { + var payload = { name: this.tableName }; + var url = configuration.BASE_URL + '/api/v1/tables'; + var headers = { + 'Host' : configuration.HOST, + 'Content-Type': 'application/json', + 'Accept' : 'application/json' + } + casper.thenOpen(tools.auth(url), { + method: 'post', + data: JSON.stringify(payload), + headers: headers + }) + + casper.then(function() { + response = JSON.parse(casper.getPageContent()); + }) + } + + return this; + } +} + diff --git a/spec/smokes/helpers/tools.js b/spec/smokes/helpers/tools.js new file mode 100644 index 0000000000..f9ea6031c3 --- /dev/null +++ b/spec/smokes/helpers/tools.js @@ -0,0 +1,5 @@ +module.exports = { + auth: function(url) { + return(url + "?api_key=" + configuration.API_KEY); + } +} diff --git a/spec/smokes/visualizations/01_create_visualization.js b/spec/smokes/visualizations/01_create_visualization.js index ccc44ec7c2..7bcd5f0dfa 100644 --- a/spec/smokes/visualizations/01_create_visualization.js +++ b/spec/smokes/visualizations/01_create_visualization.js @@ -1,8 +1,5 @@ var configuration = require("./spec/smokes/configuration") - -var authenticated = function(url) { - return(url + "?api_key=" + configuration.API_KEY); -} +var tools = require("./spec/smokes/helpers/tools") var url = configuration.BASE_URL + '/api/v1/viz'; var payload = { @@ -20,7 +17,7 @@ var headers = { casper.echo(configuration.HOST) casper.start() -casper.open(authenticated(url), { +casper.open(tools.auth(url), { method: 'post', data: JSON.stringify(payload), headers: headers @@ -28,9 +25,11 @@ casper.open(authenticated(url), { casper.then(function() { response = JSON.parse(casper.getPageContent()); - casper.test.assertEquals(response['name'], payload['name']); - require('utils').dump(response); + casper.test.assertHttpStatus(200, "Visualization creation should return 200"); + casper.test.assertEquals(response['name'], payload['name'], "Visualization should be named as we wanted"); }); -casper.run(); +casper.run(function() { + casper.test.done(2); +}); diff --git a/spec/smokes/visualizations/02_create_visualization_from_list_of_tables.js b/spec/smokes/visualizations/02_create_visualization_from_list_of_tables.js new file mode 100644 index 0000000000..e12aae513b --- /dev/null +++ b/spec/smokes/visualizations/02_create_visualization_from_list_of_tables.js @@ -0,0 +1,47 @@ +var configuration = require("./spec/smokes/configuration"); +var tables = require("./spec/smokes/helpers/table"); + +var url = configuration.BASE_URL + '/api/v1/viz'; +var payload = { + name: 'Visualization', + tables: ['table1', 'table2'] +}; + +var headers = { + 'Host' : configuration.HOST, + 'Content-Type': 'application/json', + 'Accept' : 'application/json' +}; + +casper.echo(configuration.HOST); +casper.start(); + +casper.thenOpen(tools.auth(url), { + method: 'post', + data: JSON.stringify(payload), + headers: headers +}).then(function() { + this.test.assertHttpStatus(404, "Create visualization from non-existing table should fail"); +}); + +tables.removeAllTables(); + +var table = new tables.Table(); +table.create(); + + +casper.thenOpen(tools.auth(url), { + method: 'post', + data: JSON.stringify({name: 'Visualization', tables: [table.tableName]}), + headers: headers +}) +casper.then(function() { + this.test.assertHttpStatus(200, "Visualization from new table should be created"); +}) + +tables.removeAllTables(); + +casper.run(function() { + casper.test.done(2); +}); +