Added automation for mongoDB queries (#5810)

* init

* Add spec

* Add DS common utils

* Add mongoDB utils
This commit is contained in:
Midhun Kumar E 2023-03-22 16:11:42 +05:30 committed by GitHub
parent e3d4ef82f6
commit 24ef6a1f73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 253 additions and 15 deletions

View file

@ -6,7 +6,15 @@ import {
fillDataSourceTextField,
selectDataSource,
} from "Support/utils/postgreSql";
import { verifyCouldnotConnectWithAlert } from "Support/utils/dataSource";
import { connectMongo, openMongoQueryEditor,selectQueryType } from "Support/utils/mongoDB";
import {
verifyCouldnotConnectWithAlert,
resizeQueryPanel,
query,
verifypreview,
addInput,
} from "Support/utils/dataSource";
describe("Data source MongoDB", () => {
beforeEach(() => {
@ -93,18 +101,18 @@ describe("Data source MongoDB", () => {
postgreSqlText.buttonTextTestConnection
)
.click();
cy.get(postgreSqlSelector.connectionFailedText, {timeout:70000}).verifyVisibleElement(
"have.text",
postgreSqlText.couldNotConnect,
{ timeout: 65000 }
);
cy.get(postgreSqlSelector.connectionFailedText, {
timeout: 70000,
}).verifyVisibleElement("have.text", postgreSqlText.couldNotConnect, {
timeout: 65000,
});
cy.get(postgreSqlSelector.buttonSave).verifyVisibleElement(
"have.text",
postgreSqlText.buttonTextSave
);
cy.get(postgreSqlSelector.dangerAlertNotSupportSSL).verifyVisibleElement(
"have.text",
'connect ECONNREFUSED ::1:27017'
"connect ECONNREFUSED ::1:27017"
);
cy.get('[data-cy="query-select-dropdown"]').type(
mongoDbText.optionConnectUsingConnectionString
@ -132,11 +140,11 @@ describe("Data source MongoDB", () => {
postgreSqlText.buttonTextTestConnection
)
.click();
cy.get(postgreSqlSelector.connectionFailedText, { timeout: 70000 }).verifyVisibleElement(
"have.text",
postgreSqlText.couldNotConnect,
{ timeout: 95000 }
);
cy.get(postgreSqlSelector.connectionFailedText, {
timeout: 70000,
}).verifyVisibleElement("have.text", postgreSqlText.couldNotConnect, {
timeout: 95000,
});
cy.get(postgreSqlSelector.dangerAlertNotSupportSSL).verifyVisibleElement(
"have.text",
'Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"'
@ -185,4 +193,166 @@ describe("Data source MongoDB", () => {
.invoke("show")
.should("be.visible");
});
it.only("Should verify the queries of MongoDB.", () => {
connectMongo();
openMongoQueryEditor();
resizeQueryPanel();
selectQueryType('Delete Many')
addInput('collection', 'test')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
selectQueryType('List Collections')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
query('preview')
verifypreview('raw','[{"name":"test"') //'root:[] 0 items'
selectQueryType('Insert One')
addInput('collection', 'test')
addInput('document', '{name:"mike"}')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
query('preview')
verifypreview('raw','{"acknowledged":true,"insertedId"')
selectQueryType('Find One')
addInput('collection', 'test')
addInput('filter', '{name:"mike"}')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
query('preview')
verifypreview('raw','"name":"mike"}')
selectQueryType('Find many')
addInput('collection', 'test')
addInput('filter', '{name:"mike"}')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
query('preview')
verifypreview('raw','"name":"mike"}')
selectQueryType('Total Count')
addInput('collection', 'test')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
query('preview')
verifypreview('raw','{"count":')
selectQueryType('Count')
addInput('collection', 'test')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
query('preview')
verifypreview('raw','{"count":');
selectQueryType('Distinct')
addInput('collection', 'test')
addInput('field', 'name')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
query('preview')
verifypreview('raw','["mike"]');
selectQueryType('Insert Many')
addInput('collection', 'test')
addInput('documents', '[{_id:331, name:"Nina"},{_id:441, name:"mina"}, {_id:4441, name:"Steph"}, {_id:41, name:"Mark"},{_id:3131, name:"Lina"}]')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
addInput('documents', '[{_id:3113, name:"Nina"},{_id:414, name:"mina"}]')
query('preview')
verifypreview('raw','{"acknowledged":true,"insertedCount":2,"insertedIds":{"0":3113,"1":414}}');
selectQueryType('Update One')
addInput('collection', 'test')
addInput('filter', '{name:"mina"}')
addInput('update', '{$set:{name: "mike2023"}}')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
query('preview')
verifypreview('raw','{"acknowledged":true,"modifiedCount":1,"upsertedId":null,"upsertedCount":0');
selectQueryType('Update Many')
addInput('collection', 'test')
addInput('filter', '{name:"Nina"}')
addInput('update', '{$set:{name: "mike22222"}}')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
addInput('filter', '{name:"mike22222"}')
addInput('update', '{$set:{name: "Mark"}}')
query('preview')
verifypreview('raw','{"acknowledged":true,"modifiedCount":2,"upsertedId":null,"upsertedCount":0');
selectQueryType('Replace One')
addInput('collection', 'test')
addInput('filter', '{name:"mike"}')
addInput('replacement', '{name: "mike2023"}')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
addInput('filter', '{name:"mike"}')
addInput('replacement', '{name: "Nina"}')
query('preview')
verifypreview('raw','{"acknowledged":true,"modifiedCount":1,"upsertedId":null,"upsertedCount":0');
selectQueryType('Find One and Update')
addInput('collection', 'test')
addInput('filter', '{name:"mike"}')
addInput('update', '{$set:{name: "mike2023"}}')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
addInput('filter', '{name:"Mark"}')
addInput('update', '{$set:{name: "Nina"}}')
query('preview')
verifypreview('raw','{"lastErrorObject":{"n":1,"updatedExisting":true},"value":{"_id":');
selectQueryType('Find One and Replace')
addInput('collection', 'test')
addInput('filter', '{name:"mike"}')
addInput('replacement', '{name: "mike2023"}')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
addInput('filter', '{name:"mike2023"}')
addInput('replacement', '{name: "Nina"}')
query('preview')
verifypreview('raw','{"lastErrorObject":{"n":1,"updatedExisting":true},"value":{"_id":');
selectQueryType('Find One and Delete')
addInput('collection', 'test')
addInput('filter', '{name:"Nina"}')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
addInput('filter', '{name:"mike2023"}')
query('preview')
verifypreview('raw','{"lastErrorObject":{"n":1},"value":{"_id":');
selectQueryType('Delete One')
addInput('collection', 'test')
addInput('filter', '{name:"mike"}')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
addInput('filter', '{name:"Lina"}')
query('preview')
verifypreview('raw','{"acknowledged":true,"deletedCount":1}');
selectQueryType('Aggregate')
addInput('collection', 'test')
addInput('pipeline', '[{$match:{name:"mike2023"}}, {$match:{_id:414}}]')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
query('preview')
verifypreview('raw','[{"_id":414,"name":"mike2023"}]');
selectQueryType('Operations')
addInput('collection', 'test')
addInput('operations', '[{insertOne:{name:"midhun"}}]')
query('run')
cy.verifyToastMessage('.go2072408551','Query (mongodb1) completed.')
query('preview')
verifypreview('raw','{"ok":1,"writeErrors":[],"writeConcernErrors":[],"insertedIds":[{"index":');
});
});

View file

@ -25,7 +25,7 @@ Cypress.Commands.add("forceClickOnCanvas", () => {
});
Cypress.Commands.add("verifyToastMessage", (selector, message) => {
cy.get(selector).eq(0).should("be.visible").and("have.text", message);
cy.get(selector).eq(0).should("be.visible").and("contain.text", message);
cy.get("body").then(($body) => {
if ($body.find(commonSelectors.toastCloseButton).length > 0) {
cy.closeToastMessage();

View file

@ -9,6 +9,23 @@ export const verifyCouldnotConnectWithAlert = (dangerText) => {
});
cy.get(postgreSqlSelector.dangerAlertNotSupportSSL)
.should("be.visible")
.invoke("text")
.contain(dangerText);
.contains(dangerText);
};
export const resizeQueryPanel=(height='90')=>{
cy.get('[class="query-pane"]').invoke("css", "height", `calc(${height}%)`);
}
export const query=(operation)=>{
cy.get(`[data-cy="query-${operation}-button"]`).click()
}
export const verifypreview=(type,data)=>{
cy.get(`[data-cy="preview-tab-${type}"]`).click()
cy.get(`[data-cy="preview-${type}-data-container"]`).verifyVisibleElement('contain.text', data)
}
export const addInput=(field,data)=>{
cy.get(`[data-cy="${field.toLowerCase()}-input-field"]`).clearAndTypeOnCodeMirror(data)
}

View file

@ -0,0 +1,51 @@
import {
fillDataSourceTextField,
selectDataSource,
} from "Support/utils/postgreSql";
import { mongoDbText } from "Texts/mongoDb";
import { postgreSqlSelector } from "Selectors/postgreSql";
import { postgreSqlText } from "Texts/postgreSql";
export const connectMongo = () => {
selectDataSource(mongoDbText.mongoDb);
cy.clearAndType(
'[data-cy="data-source-name-input-filed"]',
mongoDbText.cypressMongoDb
);
cy.get('[data-cy="query-select-dropdown"]').type(
mongoDbText.optionConnectUsingConnectionString
);
fillDataSourceTextField(
mongoDbText.labelConnectionString,
mongoDbText.connectionStringPlaceholder,
Cypress.env("mongodb_connString"),
"contain",
{ parseSpecialCharSequences: false, delay: 0 }
);
cy.get(postgreSqlSelector.buttonTestConnection).click();
cy.get(postgreSqlSelector.textConnectionVerified, {
timeout: 10000,
}).should("have.text", postgreSqlText.labelConnectionVerified);
cy.get(postgreSqlSelector.buttonSave).click();
cy.get(postgreSqlSelector.leftSidebarDatasourceButton).click();
cy.get(postgreSqlSelector.datasourceLabelOnList)
.should("have.text", mongoDbText.cypressMongoDb)
.find("button")
.invoke("show")
.should("be.visible");
};
export const openMongoQueryEditor = (dbName = mongoDbText.cypressMongoDb) => {
cy.get(postgreSqlSelector.buttonAddNewQueries).click();
cy.get(`[data-cy="${dbName}-add-query-card"]`)
.should("contain", dbName)
.click();
};
export const selectQueryType = (type) => {
cy.get('[data-cy="query-select-dropdown"]').click().type(`${type}{enter}`);
};