Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/client/cypress/fixtures/datasources.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions app/client/cypress/init-mysql-dump-for-test.sql
Original file line number Diff line number Diff line change
@@ -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', '');

Original file line number Diff line number Diff line change
@@ -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);
});
});
2 changes: 2 additions & 0 deletions app/client/cypress/locators/DatasourcesEditor.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion app/client/cypress/setup-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
# cat /github/home/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/config/app.yml
26 changes: 26 additions & 0 deletions app/client/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down