diff --git a/app/client/cypress/fixtures/datasources.json b/app/client/cypress/fixtures/datasources.json index 419c7106286c..a8597fa6c414 100644 --- a/app/client/cypress/fixtures/datasources.json +++ b/app/client/cypress/fixtures/datasources.json @@ -10,6 +10,11 @@ "postgres-databaseName": "fakeapi", "postgres-username": "postgres", "postgres-password": "postgres", + "mysql-host": "localhost", + "mysql-port": 3306, + "mysql-databaseName": "fakeapi", + "mysql-username": "root", + "mysql-password": "root123", "restapi-url": "https://my-json-server.typicode.com/typicode/demo/posts", "mongo-defaultDatabaseName": "sample_airbnb", "connection-type": "Replica set", diff --git a/app/client/cypress/init-mysql-dump-for-test.sql b/app/client/cypress/init-mysql-dump-for-test.sql new file mode 100644 index 000000000000..f90f190d1710 --- /dev/null +++ b/app/client/cypress/init-mysql-dump-for-test.sql @@ -0,0 +1,40 @@ +CREATE DATABASE fakeapi; +use fakeapi; + +CREATE TABLE configs ( + id int NOT NULL AUTO_INCREMENT, + configName varchar(255) NOT NULL, + configJson JSON, + configVersion int , + updatedAt TIMESTAMP, + updatedBy varchar(255), + primary key (id) +); + +CREATE TABLE users ( + id int NOT NULL AUTO_INCREMENT, + name varchar(255), + createdAt datetime, + updatedAt datetime, + status varchar(255), + gender varchar(255), + avatar varchar(255), + email varchar(255), + address varchar(255), + role varchar(255), + dob date, + phoneNo varchar(255), + primary key (id) +); + + +insert into configs (id, configName, configJson, configVersion, updatedAt, updatedBy) +values (3, 'New Config', '{"key": "val1"}', 1, '2020-08-26 11:14:28', ''), +(5, 'New Config', '{"key": "val2"}', 1, '2020-08-26 11:14:28', ''); + + +insert into users (id, name, createdAt, updatedAt, status, gender, avatar, email, address, role, dob, phoneNo) values +(7, 'Test user 7', '2019-08-07 21:36:27', '2019-10-21 03:23:42', 'APPROVED', 'Male', 'https://robohash.org/quiofficiadicta.jpg?size=100x100&set=set1' ,'xkainz6@ihg.com', '19624 Scofield Way', 'Admin','1993-08-14', ''), +(8, 'Test user 8', '2019-08-07 21:36:27', '2019-10-21 03:23:42', 'APPROVED', 'Male', 'https://robohash.org/quiofficiadicta.jpg?size=100x100&set=set1' ,'xkainz6@ihg.com', '19624 Scofield Way', 'Admin','1993-08-14', ''), +(9, 'Test user 9', '2019-08-07 21:36:27', '2019-10-21 03:23:42', 'APPROVED', 'Male', 'https://robohash.org/quiofficiadicta.jpg?size=100x100&set=set1' ,'xkainz6@ihg.com', '19624 Scofield Way', 'Admin','1993-08-14', ''); + diff --git a/app/client/cypress/integration/Smoke_TestSuite/ServerSideTests/Datasources/MySQL_spec.js b/app/client/cypress/integration/Smoke_TestSuite/ServerSideTests/Datasources/MySQL_spec.js new file mode 100644 index 000000000000..36671403cae3 --- /dev/null +++ b/app/client/cypress/integration/Smoke_TestSuite/ServerSideTests/Datasources/MySQL_spec.js @@ -0,0 +1,56 @@ +const datasource = require("../../../../locators/DatasourcesEditor.json"); +const queryEditor = require("../../../../locators/QueryEditor.json"); +const datasourceEditor = require("../../../../locators/DatasourcesEditor.json"); + +let datasourceName; + +describe("MySQL datasource test cases", function() { + beforeEach(() => { + cy.startRoutesForDatasource(); + }); + + it("Create, test, save then delete a MySQL datasource", function() { + cy.NavigateToDatasourceEditor(); + cy.get(datasource.MySQL).click(); + cy.getPluginFormsAndCreateDatasource(); + cy.fillMySQLDatasourceForm(); + cy.get("@createDatasource").then((httpResponse) => { + datasourceName = httpResponse.response.body.data.name; + }); + cy.testSaveDatasource(); + }); + + it("Create with trailing white spaces in host address and database name, test, save then delete a MySQL datasource", function() { + cy.NavigateToDatasourceEditor(); + cy.get(datasource.MySQL).click(); + cy.getPluginFormsAndCreateDatasource(); + cy.fillMySQLDatasourceForm(true); + cy.get("@createDatasource").then((httpResponse) => { + datasourceName = httpResponse.response.body.data.name; + }); + cy.testSaveDatasource(); + }); + + it("Create a new query from the datasource editor", function() { + cy.saveDatasource(); + // cy.get(datasource.createQuerty).click(); + cy.get(`${datasourceEditor.datasourceCard} ${datasource.createQuerty}`) + .last() + .click(); + cy.wait("@createNewApi").should( + "have.nested.property", + "response.body.responseMeta.status", + 201, + ); + + cy.get(queryEditor.queryMoreAction).click(); + cy.get(queryEditor.deleteUsingContext).click(); + cy.wait("@deleteAction").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + + cy.deleteDatasource(datasourceName); + }); +}); diff --git a/app/client/cypress/locators/DatasourcesEditor.json b/app/client/cypress/locators/DatasourcesEditor.json index 1674290d3154..54476e1426d0 100644 --- a/app/client/cypress/locators/DatasourcesEditor.json +++ b/app/client/cypress/locators/DatasourcesEditor.json @@ -10,8 +10,10 @@ "MongoDB": ".t--plugin-name:contains('MongoDB')", "RESTAPI": ".t--plugin-name:contains('REST API')", "PostgreSQL": ".t--plugin-name:contains('PostgreSQL')", + "MySQL": ".t--plugin-name:contains('Mysql')", "sectionAuthentication": "[data-cy=section-Authentication]", "PostgresEntity": ".t--entity-name:contains(PostgreSQL)", + "MySQLEntity": ".t--entity-name:contains(Mysql)", "createQuerty": ".t--create-query", "activeDatasourceList": ".t--active-datasource-list", "datasourceCard": ".t--datasource", diff --git a/app/client/cypress/setup-test.sh b/app/client/cypress/setup-test.sh index abb2a006a3e9..6b55ad5cb370 100755 --- a/app/client/cypress/setup-test.sh +++ b/app/client/cypress/setup-test.sh @@ -35,6 +35,14 @@ sudo docker run --network host --name postgres -d -p 5432:5432 \ --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 \ postgres:latest & +sudo docker run -p 127.0.0.1:3306:3306 --name mariadb -e MARIADB_ROOT_PASSWORD=root123 -d mariadb + +echo "Sleeping for 30 seconds to let the MySQL start" +sleep 30 + +sudo docker exec -i mariadb mysql -uroot -proot123 mysql < `pwd`/cypress/init-mysql-dump-for-test.sql + + echo "Sleeping for 30 seconds to let the servers start" sleep 30 @@ -100,4 +108,4 @@ curl -k --request POST -v 'https://dev.appsmith.com/api/v1/users' \ # DEBUG=cypress:* $(npm bin)/cypress version # sed -i -e "s|api_url:.*$|api_url: $CYPRESS_URL|g" /github/home/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/config/app.yml -# cat /github/home/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/config/app.yml \ No newline at end of file +# cat /github/home/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/config/app.yml diff --git a/app/client/cypress/support/commands.js b/app/client/cypress/support/commands.js index 9dc8e468c5f6..80237961cfa7 100644 --- a/app/client/cypress/support/commands.js +++ b/app/client/cypress/support/commands.js @@ -2051,6 +2051,32 @@ Cypress.Commands.add( }, ); +Cypress.Commands.add( + "fillMySQLDatasourceForm", + (shouldAddTrailingSpaces = false) => { + const hostAddress = shouldAddTrailingSpaces + ? datasourceFormData["mysql-host"] + " " + : datasourceFormData["mysql-host"]; + const databaseName = shouldAddTrailingSpaces + ? datasourceFormData["mysql-databaseName"] + " " + : datasourceFormData["mysql-databaseName"]; + + cy.get(datasourceEditor.host).type(hostAddress); + cy.get(datasourceEditor.port).type(datasourceFormData["mysql-port"]); + cy.get(datasourceEditor.databaseName) + .clear() + .type(databaseName); + + cy.get(datasourceEditor.sectionAuthentication).click(); + cy.get(datasourceEditor.username).type( + datasourceFormData["mysql-username"], + ); + cy.get(datasourceEditor.password).type( + datasourceFormData["mysql-password"], + ); + }, +); + Cypress.Commands.add( "fillUsersMockDatasourceForm", (shouldAddTrailingSpaces = false) => {