Browse Source

test: webhook- add wait for webhook to get triggered

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/3655/head
Raju Udava 2 years ago
parent
commit
fbceea976b
  1. 777
      scripts/cypress/integration/common/8a_webhook.js

777
scripts/cypress/integration/common/8a_webhook.js

@ -6,422 +6,441 @@ import { loginPage } from "../../support/page_objects/navigation";
let hookPath = "http://localhost:9090/hook"; let hookPath = "http://localhost:9090/hook";
function createWebhook(hook, test) { function createWebhook(hook, test) {
cy.get('.nc-actions-menu-btn').should('exist').click(); cy.get(".nc-actions-menu-btn").should("exist").click();
cy.getActiveMenu(".nc-dropdown-actions-menu").find('.ant-dropdown-menu-title-content').contains('Webhooks').click() cy.getActiveMenu(".nc-dropdown-actions-menu")
.find(".ant-dropdown-menu-title-content")
// cy.get(".nc-btn-webhook").should("exist").click(); .contains("Webhooks")
cy.get(".nc-btn-create-webhook").should("exist").click(); .click();
// hardcode "Content-type: application/json" // cy.get(".nc-btn-webhook").should("exist").click();
cy.get(".ant-tabs-tab-btn").contains("Headers").should("exist").click(); cy.get(".nc-btn-create-webhook").should("exist").click();
// kludge : as neither scrollIntoView nor scrollTo didn't yield any results // hardcode "Content-type: application/json"
// cy.getActiveSelection().find('.ant-select-item').contains('Content-Type).scrollIntoView(); cy.get(".ant-tabs-tab-btn").contains("Headers").should("exist").click();
// cy.getActiveSelection().find('.rc-virtual-list').scrollTo('center');
// cy.getActiveSelection().select('Content-Type', { force: true }); // kludge : as neither scrollIntoView nor scrollTo didn't yield any results
// cy.getActiveSelection().find('.ant-select-item').contains('Content-Type).scrollIntoView();
cy.get(".nc-input-hook-header-key") // cy.getActiveSelection().find('.rc-virtual-list').scrollTo('center');
.should("exist") // cy.getActiveSelection().select('Content-Type', { force: true });
.click()
.type('{downarrow}') cy.get(".nc-input-hook-header-key")
.type('{downarrow}') .should("exist")
.type('{downarrow}') .click()
.type('{downarrow}') .type("{downarrow}")
.type('{downarrow}') .type("{downarrow}")
.type('{downarrow}') .type("{downarrow}")
.type('{downarrow}') .type("{downarrow}")
.type('{downarrow}') .type("{downarrow}")
.type('{downarrow}') .type("{downarrow}")
.type('{downarrow}') .type("{downarrow}")
.type('{downarrow}') .type("{downarrow}")
.type('{downarrow}') .type("{downarrow}")
.type("{downarrow}")
cy.getActiveSelection('.nc-dropdown-webhook-header').find('.ant-select-item-option-content').contains('Content-Type').should('exist').click(); .type("{downarrow}")
.type("{downarrow}");
cy.get("input.nc-input-hook-header-value")
.should("exist") cy.getActiveSelection(".nc-dropdown-webhook-header")
.clear({ force: true }) .find(".ant-select-item-option-content")
.type("application/json", { force: true }); .contains("Content-Type")
.should("exist")
cy.get('.nc-hook-header-tab-checkbox').find('input.ant-checkbox-input').should('exist').click(); .click();
// common routine for both create & modify to configure hook cy.get("input.nc-input-hook-header-value")
configureWebhook(hook, test); .should("exist")
.clear({ force: true })
.type("application/json", { force: true });
cy.get(".nc-hook-header-tab-checkbox")
.find("input.ant-checkbox-input")
.should("exist")
.click();
// common routine for both create & modify to configure hook
configureWebhook(hook, test);
} }
function deleteWebhook(index) { function deleteWebhook(index) {
cy.get('.nc-actions-menu-btn').should('exist').click(); cy.get(".nc-actions-menu-btn").should("exist").click();
cy.getActiveMenu(".nc-dropdown-actions-menu").find('.ant-dropdown-menu-title-content').contains('Webhooks').click() cy.getActiveMenu(".nc-dropdown-actions-menu")
.find(".ant-dropdown-menu-title-content")
cy.get(".nc-hook-delete-icon").eq(index).click({ force: true }); .contains("Webhooks")
cy.toastWait("Hook deleted successfully"); .click();
cy.get("body").type("{esc}");
cy.get(".nc-hook-delete-icon").eq(index).click({ force: true });
cy.toastWait("Hook deleted successfully");
cy.get("body").type("{esc}");
} }
function openWebhook(index) { function openWebhook(index) {
cy.get('.nc-actions-menu-btn').should('exist').click(); cy.get(".nc-actions-menu-btn").should("exist").click();
cy.getActiveMenu(".nc-dropdown-actions-menu").find('.ant-dropdown-menu-title-content').contains('Webhooks').click() cy.getActiveMenu(".nc-dropdown-actions-menu")
.find(".ant-dropdown-menu-title-content")
.contains("Webhooks")
.click();
cy.get(".nc-hook").eq(index).click({ force: true }); cy.get(".nc-hook").eq(index).click({ force: true });
} }
function configureWebhook(hook, test) { function configureWebhook(hook, test) {
// configure what ever is present. ignore rest // configure what ever is present. ignore rest
// currently works for only URL type // currently works for only URL type
if (hook?.title) {
cy.get(".nc-text-field-hook-title")
.should("exist")
.clear()
.type(hook.title);
}
if (hook?.event) { if (hook?.title) {
cy.get(".nc-text-field-hook-event").should("exist").click(); cy.get(".nc-text-field-hook-title")
cy.getActiveSelection('.nc-dropdown-webhook-event') .should("exist")
.find(`.ant-select-item`) .clear()
.contains(hook.event) .type(hook.title);
.should("exist") }
.click();
} if (hook?.event) {
cy.get(".nc-text-field-hook-event").should("exist").click();
cy.getActiveSelection(".nc-dropdown-webhook-event")
.find(`.ant-select-item`)
.contains(hook.event)
.should("exist")
.click();
}
if (hook?.url?.path) { if (hook?.url?.path) {
cy.get(".nc-text-field-hook-url-path") cy.get(".nc-text-field-hook-url-path")
.should("exist") .should("exist")
.clear() .clear()
.type(hook.url.path); .type(hook.url.path);
} }
if (hook?.deleteCondition === true) { if (hook?.deleteCondition === true) {
cy.get(".nc-filter-item-remove-btn") cy.get(".nc-filter-item-remove-btn").should("exist").click({ force: true });
.should("exist") }
.click({ force: true });
}
if (hook?.condition) { if (hook?.condition) {
cy.get(".nc-check-box-hook-condition").should("exist").click(); cy.get(".nc-check-box-hook-condition").should("exist").click();
cy.get(".menu-filter-dropdown") cy.get(".menu-filter-dropdown")
.last() .last()
.find("button") .find("button")
.contains("Add Filter") .contains("Add Filter")
.click(); .click();
cy.get(".nc-filter-field-select") cy.get(".nc-filter-field-select").should("exist").last().click();
.should("exist") cy.get(".ant-select-dropdown:visible")
.last() .should("exist")
.click() .find(`.ant-select-item`)
cy.get('.ant-select-dropdown:visible') .contains(new RegExp("^" + hook.condition.column + "$", "g"))
.should('exist') .should("exist")
.find(`.ant-select-item`) .click();
.contains(new RegExp("^" + hook.condition.column + "$", "g")) cy.wait(1000);
.should('exist')
.click();
cy.wait(1000);
cy.get(".nc-filter-operation-select").should("exist").last().click();
cy.get('.ant-select-dropdown:visible')
.should('exist')
.find(`.ant-select-item`)
.contains(hook.condition.operator)
.should('exist')
.click();
if (hook.condition.operator != "is null" && hook.condition.operator != "is not null") {
cy.get(".nc-filter-value-select")
.should("exist")
.last()
.type(hook.condition.value);
cy.get(".nc-filter-operation-select").last().click();
}
}
if (test) { cy.get(".nc-filter-operation-select").should("exist").last().click();
cy.get(".nc-btn-webhook-test").should("exist").click(); cy.get(".ant-select-dropdown:visible")
cy.toastWait("Webhook tested successfully"); .should("exist")
.find(`.ant-select-item`)
.contains(hook.condition.operator)
.should("exist")
.click();
if (
hook.condition.operator != "is null" &&
hook.condition.operator != "is not null"
) {
cy.get(".nc-filter-value-select")
.should("exist")
.last()
.type(hook.condition.value);
cy.get(".nc-filter-operation-select").last().click();
} }
}
cy.get(".nc-btn-webhook-save").should("exist").click(); if (test) {
cy.toastWait("Webhook details updated successfully"); cy.get(".nc-btn-webhook-test").should("exist").click();
cy.get(".nc-icon-hook-navigate-left").should("exist").click(); cy.toastWait("Webhook tested successfully");
cy.get("body").type("{esc}"); }
cy.get(".nc-btn-webhook-save").should("exist").click();
cy.toastWait("Webhook details updated successfully");
cy.get(".nc-icon-hook-navigate-left").should("exist").click();
cy.get("body").type("{esc}");
} }
function clearServerData() { function clearServerData() {
// clear stored data in server // clear stored data in server
cy.request("http://localhost:9090/hook/clear"); cy.request("http://localhost:9090/hook/clear");
// ensure stored message count is 0 // ensure stored message count is 0
cy.request("http://localhost:9090/hook/count").then((msg) => { cy.request("http://localhost:9090/hook/count").then((msg) => {
cy.log(msg.body); cy.log(msg.body);
expect(msg.body).to.equal(0); expect(msg.body).to.equal(0);
}); });
} }
function addNewRow(index, cellValue) { function addNewRow(index, cellValue) {
cy.get(".nc-add-new-row-btn:visible").should("exist"); cy.get(".nc-add-new-row-btn:visible").should("exist");
cy.get(".nc-add-new-row-btn").click(); cy.get(".nc-add-new-row-btn").click();
cy.wait(1000); cy.wait(1000);
cy.get(".nc-expand-col-Title").find(".nc-cell > input").first().type(cellValue); cy.get(".nc-expand-col-Title")
cy.getActiveDrawer('.nc-drawer-expanded-form') .find(".nc-cell > input")
.find(".ant-btn-primary") .first()
.click(); .type(cellValue);
cy.getActiveDrawer(".nc-drawer-expanded-form")
cy.toastWait("updated successfully"); .find(".ant-btn-primary")
cy.getActiveDrawer('.nc-drawer-expanded-form') .click();
.find(".ant-btn")
.contains("Cancel") cy.toastWait("updated successfully");
.click(); cy.getActiveDrawer(".nc-drawer-expanded-form")
mainPage.getCell("Title", index).contains(cellValue).should("exist"); .find(".ant-btn")
.contains("Cancel")
.click();
mainPage.getCell("Title", index).contains(cellValue).should("exist");
} }
function updateRow(index, cellValue) { function updateRow(index, cellValue) {
cy.get(".nc-row-expand") cy.get(".nc-row-expand")
.eq(index-1) .eq(index - 1)
.click({ force: true }); .click({ force: true });
cy.get(".nc-expand-col-Title").find(".nc-cell > input") cy.get(".nc-expand-col-Title")
.should("exist") .find(".nc-cell > input")
.first() .should("exist")
.clear() .first()
.type(cellValue); .clear()
.type(cellValue);
cy.getActiveDrawer('.nc-drawer-expanded-form')
.find("button") cy.getActiveDrawer(".nc-drawer-expanded-form")
.contains("Save row") .find("button")
.click({ force: true }); .contains("Save row")
.click({ force: true });
// partial toast message
cy.toastWait("updated successfully"); // partial toast message
cy.getActiveDrawer('.nc-drawer-expanded-form') cy.toastWait("updated successfully");
.find("button") cy.getActiveDrawer(".nc-drawer-expanded-form")
.contains("Cancel") .find("button")
.click({ force: true }); .contains("Cancel")
.click({ force: true });
} }
function verifyHookTrigger(count, lastValue) { function verifyHookTrigger(count, lastValue) {
cy.request("http://localhost:9090/hook/count").then((msg) => { // allow message to be received
cy.log(msg.body); cy.wait(500);
expect(msg.body).to.equal(count);
cy.request("http://localhost:9090/hook/count").then((msg) => {
cy.log(msg.body);
expect(msg.body).to.equal(count);
});
if (count) {
cy.request("http://localhost:9090/hook/last").then((msg) => {
cy.log(msg.body);
expect(msg.body.Title).to.equal(lastValue);
}); });
if (count) { }
cy.request("http://localhost:9090/hook/last").then((msg) => {
cy.log(msg.body);
expect(msg.body.Title).to.equal(lastValue);
});
}
} }
function deleteRow(index) { function deleteRow(index) {
mainPage mainPage.getCell("Title", index).rightclick();
.getCell("Title", index)
.rightclick(); // delete row
cy.getActiveMenu(".nc-dropdown-grid-context-menu")
// delete row .find('.ant-dropdown-menu-item:contains("Delete Row")')
cy.getActiveMenu(".nc-dropdown-grid-context-menu") .first()
.find('.ant-dropdown-menu-item:contains("Delete Row")') .click();
.first()
.click({ force: true });
} }
export const genTest = (apiType, dbType) => { export const genTest = (apiType, dbType) => {
if (!isTestSuiteActive(apiType, dbType)) return; if (!isTestSuiteActive(apiType, dbType)) return;
describe(`Webhook`, () => { describe(`Webhook`, () => {
before(() => { before(() => {
loginPage.loginAndOpenProject(apiType, dbType); loginPage.loginAndOpenProject(apiType, dbType);
cy.createTable("Temp"); cy.createTable("Temp");
cy.saveLocalStorage(); cy.saveLocalStorage();
}); });
beforeEach(() => { beforeEach(() => {
cy.restoreLocalStorage(); cy.restoreLocalStorage();
}); });
afterEach(() => { afterEach(() => {
cy.saveLocalStorage(); cy.saveLocalStorage();
}) });
after(() => { after(() => {
cy.restoreLocalStorage(); cy.restoreLocalStorage();
cy.deleteTable("Temp"); cy.deleteTable("Temp");
cy.saveLocalStorage(); cy.saveLocalStorage();
}); });
it("Create: 'After Insert' event", () => { it("Create: 'After Insert' event", () => {
createWebhook({ createWebhook({
title: "hook-1", title: "hook-1",
event: "After Insert", event: "After Insert",
type: "URL", type: "URL",
url: { url: {
method: "POST", method: "POST",
path: hookPath, path: hookPath,
}, },
}); });
clearServerData(); clearServerData();
addNewRow(1, "Poole"); addNewRow(1, "Poole");
verifyHookTrigger(1, "Poole"); verifyHookTrigger(1, "Poole");
updateRow(1, "Delaware"); updateRow(1, "Delaware");
verifyHookTrigger(1, "Poole"); verifyHookTrigger(1, "Poole");
deleteRow(1); deleteRow(1);
verifyHookTrigger(1, "Poole"); verifyHookTrigger(1, "Poole");
}); });
it("Add 'After Update' event", () => { it("Add 'After Update' event", () => {
createWebhook({ createWebhook({
title: "hook-2", title: "hook-2",
event: "After Update", event: "After Update",
type: "URL", type: "URL",
url: { url: {
method: "POST", method: "POST",
path: hookPath, path: hookPath,
}, },
}); });
clearServerData(); clearServerData();
addNewRow(1, "Poole"); addNewRow(1, "Poole");
verifyHookTrigger(1, "Poole"); verifyHookTrigger(1, "Poole");
updateRow(1, "Delaware"); updateRow(1, "Delaware");
verifyHookTrigger(2, "Delaware"); verifyHookTrigger(2, "Delaware");
deleteRow(1); deleteRow(1);
verifyHookTrigger(2, "Delaware"); verifyHookTrigger(2, "Delaware");
}); });
it("Add 'After Delete' event", () => { it("Add 'After Delete' event", () => {
createWebhook({ createWebhook({
title: "hook-3", title: "hook-3",
event: "After Delete", event: "After Delete",
type: "URL", type: "URL",
url: { url: {
method: "POST", method: "POST",
path: hookPath, path: hookPath,
}, },
}); });
clearServerData(); clearServerData();
addNewRow(1, "Poole"); addNewRow(1, "Poole");
verifyHookTrigger(1, "Poole"); verifyHookTrigger(1, "Poole");
updateRow(1, "Delaware"); updateRow(1, "Delaware");
verifyHookTrigger(2, "Delaware"); verifyHookTrigger(2, "Delaware");
deleteRow(1); deleteRow(1);
verifyHookTrigger(3, "Delaware"); verifyHookTrigger(3, "Delaware");
}); });
it("Modify webhook", () => { it("Modify webhook", () => {
openWebhook(0); openWebhook(0);
configureWebhook({ event: "After Delete" }); configureWebhook({ event: "After Delete" });
openWebhook(1); openWebhook(1);
configureWebhook({ event: "After Delete" }); configureWebhook({ event: "After Delete" });
clearServerData(); clearServerData();
addNewRow(1, "Poole"); addNewRow(1, "Poole");
verifyHookTrigger(0, ""); verifyHookTrigger(0, "");
updateRow(1, "Delaware"); updateRow(1, "Delaware");
verifyHookTrigger(0, ""); verifyHookTrigger(0, "");
deleteRow(1); deleteRow(1);
verifyHookTrigger(3, "Delaware"); verifyHookTrigger(3, "Delaware");
}); });
it("Delete webhook", () => { it("Delete webhook", () => {
deleteWebhook(2); deleteWebhook(2);
deleteWebhook(1); deleteWebhook(1);
deleteWebhook(0); deleteWebhook(0);
clearServerData(); clearServerData();
addNewRow(1, "Poole"); addNewRow(1, "Poole");
verifyHookTrigger(0, ""); verifyHookTrigger(0, "");
updateRow(1, "Delaware"); updateRow(1, "Delaware");
verifyHookTrigger(0, ""); verifyHookTrigger(0, "");
deleteRow(1); deleteRow(1);
verifyHookTrigger(0, ""); verifyHookTrigger(0, "");
}); });
it("Create, with condition", () => { it("Create, with condition", () => {
// create 3 webhooks with all three events, with condition this time // create 3 webhooks with all three events, with condition this time
createWebhook({ createWebhook({
title: "hook-with-condition-1", title: "hook-with-condition-1",
event: "After Insert", event: "After Insert",
type: "URL", type: "URL",
url: { url: {
method: "POST", method: "POST",
path: hookPath, path: hookPath,
}, },
condition: { condition: {
column: "Title", column: "Title",
operator: "is like", operator: "is like",
value: "Poole", value: "Poole",
}, },
}); });
createWebhook({ createWebhook({
title: "hook-with-condition-2", title: "hook-with-condition-2",
event: "After Update", event: "After Update",
type: "URL", type: "URL",
url: { url: {
method: "POST", method: "POST",
path: hookPath, path: hookPath,
}, },
condition: { condition: {
column: "Title", column: "Title",
operator: "is like", operator: "is like",
value: "Poole", value: "Poole",
}, },
}); });
createWebhook({ createWebhook({
title: "hook-with-condition-3", title: "hook-with-condition-3",
event: "After Delete", event: "After Delete",
type: "URL", type: "URL",
url: { url: {
method: "POST", method: "POST",
path: hookPath, path: hookPath,
}, },
condition: { condition: {
column: "Title", column: "Title",
operator: "is like", operator: "is like",
value: "Poole", value: "Poole",
}, },
}); });
clearServerData(); clearServerData();
addNewRow(1, "Poole"); addNewRow(1, "Poole");
addNewRow(2, "Delaware"); addNewRow(2, "Delaware");
verifyHookTrigger(1, "Poole"); verifyHookTrigger(1, "Poole");
updateRow(1, "Delaware"); updateRow(1, "Delaware");
updateRow(2, "Poole"); updateRow(2, "Poole");
verifyHookTrigger(2, "Poole"); verifyHookTrigger(2, "Poole");
deleteRow(2); deleteRow(2);
deleteRow(1); deleteRow(1);
verifyHookTrigger(3, "Poole"); verifyHookTrigger(3, "Poole");
}); });
it("Modify trigger condition", () => { it("Modify trigger condition", () => {
openWebhook(0); openWebhook(0);
configureWebhook({ deleteCondition: true }); configureWebhook({ deleteCondition: true });
openWebhook(1); openWebhook(1);
configureWebhook({ deleteCondition: true }); configureWebhook({ deleteCondition: true });
openWebhook(2); openWebhook(2);
configureWebhook({ deleteCondition: true }); configureWebhook({ deleteCondition: true });
clearServerData(); clearServerData();
addNewRow(1, "Poole"); addNewRow(1, "Poole");
addNewRow(2, "Delaware"); addNewRow(2, "Delaware");
verifyHookTrigger(2, "Delaware"); verifyHookTrigger(2, "Delaware");
updateRow(1, "Delaware"); updateRow(1, "Delaware");
updateRow(2, "Poole"); updateRow(2, "Poole");
verifyHookTrigger(4, "Poole"); verifyHookTrigger(4, "Poole");
deleteRow(2); deleteRow(2);
deleteRow(1); deleteRow(1);
verifyHookTrigger(6, "Delaware"); verifyHookTrigger(6, "Delaware");
}); });
it("Delete trigger condition", () => { it("Delete trigger condition", () => {
deleteWebhook(2); deleteWebhook(2);
deleteWebhook(1); deleteWebhook(1);
deleteWebhook(0); deleteWebhook(0);
clearServerData(); clearServerData();
addNewRow(1, "Poole"); addNewRow(1, "Poole");
verifyHookTrigger(0, ""); verifyHookTrigger(0, "");
updateRow(1, "Delaware"); updateRow(1, "Delaware");
verifyHookTrigger(0, ""); verifyHookTrigger(0, "");
deleteRow(1); deleteRow(1);
verifyHookTrigger(0, ""); verifyHookTrigger(0, "");
});
}); });
});
}; };
/** /**

Loading…
Cancel
Save