mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
253 lines
7.4 KiB
253 lines
7.4 KiB
2 years ago
|
import { expect, test } from "@playwright/test";
|
||
2 years ago
|
import { DashboardPage } from "../pages/Dashboard";
|
||
|
import setup from "../setup";
|
||
|
import { ToolbarPage } from "../pages/Dashboard/common/Toolbar";
|
||
2 years ago
|
import makeServer from "../setup/server";
|
||
|
import { WebhookFormPage } from "../pages/Dashboard/WebhookForm";
|
||
2 years ago
|
|
||
2 years ago
|
let hookPath = "http://localhost:9090/hook";
|
||
|
|
||
|
// clear server data
|
||
|
async function clearServerData({ request }) {
|
||
|
// clear stored data in server
|
||
|
await request.get(hookPath + "/clear");
|
||
|
|
||
|
// ensure stored message count is 0
|
||
|
const response = await request.get(hookPath + "/count");
|
||
2 years ago
|
await expect(await response.json()).toBe(0);
|
||
2 years ago
|
}
|
||
|
|
||
|
async function verifyHookTrigger(count: number, value: string, request) {
|
||
2 years ago
|
// Retry since there can be lag between the time the hook is triggered and the time the server receives the request
|
||
|
let response;
|
||
|
for(let i = 0; i < 6; i++) {
|
||
|
response = await request.get(hookPath + "/count");
|
||
|
if(await response.json() === count) {
|
||
|
break;
|
||
|
}
|
||
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
||
|
}
|
||
2 years ago
|
await expect(await response.json()).toBe(count);
|
||
2 years ago
|
|
||
|
if (count) {
|
||
|
response = await request.get(hookPath + "/last");
|
||
2 years ago
|
await expect((await response.json()).Title).toBe(value);
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
test.describe.serial("Webhook", async () => {
|
||
2 years ago
|
// start a server locally for webhook tests
|
||
|
|
||
2 years ago
|
let dashboard: DashboardPage, toolbar: ToolbarPage, webhook: WebhookFormPage;
|
||
2 years ago
|
let context: any;
|
||
|
|
||
2 years ago
|
test.beforeAll(async () => {
|
||
2 years ago
|
await makeServer();
|
||
2 years ago
|
})
|
||
2 years ago
|
|
||
2 years ago
|
test.beforeEach(async ({ page }) => {
|
||
|
context = await setup({ page });
|
||
|
dashboard = new DashboardPage(page, context.project);
|
||
|
toolbar = dashboard.grid.toolbar;
|
||
2 years ago
|
webhook = dashboard.webhookForm;
|
||
2 years ago
|
});
|
||
|
|
||
2 years ago
|
test("CRUD", async ({ request }) => {
|
||
2 years ago
|
// close 'Team & Auth' tab
|
||
2 years ago
|
await clearServerData({ request });
|
||
2 years ago
|
await dashboard.closeTab({ title: "Team & Auth" });
|
||
|
await dashboard.treeView.createTable({ title: "Test" });
|
||
|
|
||
2 years ago
|
// after insert hook
|
||
|
await webhook.create({
|
||
|
title: "hook-1",
|
||
|
event: "After Insert",
|
||
|
});
|
||
|
await clearServerData({ request });
|
||
|
await dashboard.grid.addNewRow({
|
||
|
index: 0,
|
||
|
columnHeader: "Title",
|
||
|
value: "Poole",
|
||
|
});
|
||
|
await verifyHookTrigger(1, "Poole", request);
|
||
|
await dashboard.grid.editRow({ index: 0, value: "Delaware" });
|
||
|
await verifyHookTrigger(1, "Poole", request);
|
||
|
await dashboard.grid.deleteRow(0);
|
||
|
await verifyHookTrigger(1, "Poole", request);
|
||
|
|
||
|
// after update hook
|
||
|
await webhook.create({
|
||
|
title: "hook-2",
|
||
|
event: "After Update",
|
||
|
});
|
||
|
|
||
|
await clearServerData({ request });
|
||
|
await dashboard.grid.addNewRow({
|
||
|
index: 0,
|
||
|
columnHeader: "Title",
|
||
|
value: "Poole",
|
||
|
});
|
||
|
await verifyHookTrigger(1, "Poole", request);
|
||
|
await dashboard.grid.editRow({ index: 0, value: "Delaware" });
|
||
|
await verifyHookTrigger(2, "Delaware", request);
|
||
|
await dashboard.grid.deleteRow(0);
|
||
|
await verifyHookTrigger(2, "Delaware", request);
|
||
|
|
||
|
// after delete hook
|
||
|
await webhook.create({
|
||
|
title: "hook-3",
|
||
|
event: "After Delete",
|
||
|
});
|
||
|
await clearServerData({ request });
|
||
|
await dashboard.grid.addNewRow({
|
||
|
index: 0,
|
||
|
columnHeader: "Title",
|
||
|
value: "Poole",
|
||
|
});
|
||
|
await verifyHookTrigger(1, "Poole", request);
|
||
|
await dashboard.grid.editRow({ index: 0, value: "Delaware" });
|
||
|
await verifyHookTrigger(2, "Delaware", request);
|
||
|
await dashboard.grid.deleteRow(0);
|
||
|
await verifyHookTrigger(3, "Delaware", request);
|
||
|
|
||
|
// modify webhook
|
||
|
await webhook.open({ index: 0 });
|
||
|
await webhook.configureWebhook({
|
||
|
title: "hook-1-modified",
|
||
|
event: "After Delete",
|
||
|
});
|
||
|
await webhook.save();
|
||
|
await webhook.close();
|
||
|
await webhook.open({ index: 1 });
|
||
|
await webhook.configureWebhook({
|
||
|
title: "hook-2-modified",
|
||
|
event: "After Delete",
|
||
|
});
|
||
|
await webhook.save();
|
||
|
await webhook.close();
|
||
|
|
||
|
await clearServerData({ request });
|
||
|
await dashboard.grid.addNewRow({
|
||
|
index: 0,
|
||
|
columnHeader: "Title",
|
||
|
value: "Poole",
|
||
|
});
|
||
|
await verifyHookTrigger(0, "Poole", request);
|
||
|
await dashboard.grid.editRow({ index: 0, value: "Delaware" });
|
||
|
await verifyHookTrigger(0, "Delaware", request);
|
||
|
await dashboard.grid.deleteRow(0);
|
||
|
await verifyHookTrigger(3, "Delaware", request);
|
||
|
|
||
|
// delete webhook
|
||
|
await webhook.delete({ index: 0 });
|
||
|
await webhook.delete({ index: 0 });
|
||
|
await webhook.delete({ index: 0 });
|
||
|
|
||
|
await clearServerData({ request });
|
||
|
await dashboard.grid.addNewRow({
|
||
|
index: 0,
|
||
|
columnHeader: "Title",
|
||
|
value: "Poole",
|
||
|
});
|
||
|
await verifyHookTrigger(0, "", request);
|
||
|
await dashboard.grid.editRow({ index: 0, value: "Delaware" });
|
||
|
await verifyHookTrigger(0, "", request);
|
||
|
await dashboard.grid.deleteRow(0);
|
||
|
await verifyHookTrigger(0, "", request);
|
||
|
});
|
||
2 years ago
|
|
||
2 years ago
|
test("webhook Conditional webhooks", async ({ request }) => {
|
||
|
await clearServerData({ request });
|
||
2 years ago
|
// close 'Team & Auth' tab
|
||
|
await dashboard.closeTab({ title: "Team & Auth" });
|
||
|
await dashboard.treeView.createTable({ title: "Test" });
|
||
|
|
||
|
// after insert hook
|
||
|
await webhook.create({
|
||
|
title: "hook-1",
|
||
2 years ago
|
event: "After Insert",
|
||
|
});
|
||
2 years ago
|
// after insert hook
|
||
|
await webhook.create({
|
||
|
title: "hook-2",
|
||
|
event: "After Update",
|
||
|
});
|
||
|
// after insert hook
|
||
|
await webhook.create({
|
||
|
title: "hook-3",
|
||
|
event: "After Delete",
|
||
|
});
|
||
|
|
||
|
await webhook.open({ index: 0 });
|
||
|
await webhook.addCondition({
|
||
|
column: "Title",
|
||
|
operator: "is like",
|
||
|
value: "Poole",
|
||
|
save: true,
|
||
|
});
|
||
|
|
||
|
await webhook.open({ index: 1 });
|
||
|
await webhook.addCondition({
|
||
|
column: "Title",
|
||
|
operator: "is like",
|
||
|
value: "Poole",
|
||
|
save: true,
|
||
|
});
|
||
2 years ago
|
|
||
2 years ago
|
await webhook.open({ index: 2 });
|
||
|
await webhook.addCondition({
|
||
|
column: "Title",
|
||
|
operator: "is like",
|
||
|
value: "Poole",
|
||
|
save: true,
|
||
|
});
|
||
|
|
||
|
// verify
|
||
|
await clearServerData({ request });
|
||
|
await dashboard.grid.addNewRow({
|
||
|
index: 0,
|
||
|
columnHeader: "Title",
|
||
|
value: "Poole",
|
||
|
});
|
||
|
await dashboard.grid.addNewRow({
|
||
|
index: 1,
|
||
|
columnHeader: "Title",
|
||
|
value: "Delaware",
|
||
|
});
|
||
|
await verifyHookTrigger(1, "Poole", request);
|
||
|
await dashboard.grid.editRow({ index: 0, value: "Delaware" });
|
||
|
await dashboard.grid.editRow({ index: 1, value: "Poole" });
|
||
|
await verifyHookTrigger(2, "Poole", request);
|
||
|
await dashboard.grid.deleteRow(1);
|
||
|
await dashboard.grid.deleteRow(0);
|
||
|
await verifyHookTrigger(3, "Poole", request);
|
||
|
|
||
|
// Delete condition
|
||
|
await webhook.open({ index: 2 });
|
||
|
await webhook.deleteCondition({ save: true });
|
||
|
await webhook.open({ index: 1 });
|
||
|
await webhook.deleteCondition({ save: true });
|
||
|
await webhook.open({ index: 0 });
|
||
|
await webhook.deleteCondition({ save: true });
|
||
|
|
||
|
await clearServerData({ request });
|
||
|
await dashboard.grid.addNewRow({
|
||
|
index: 0,
|
||
|
columnHeader: "Title",
|
||
|
value: "Poole",
|
||
|
});
|
||
|
await dashboard.grid.addNewRow({
|
||
|
index: 1,
|
||
|
columnHeader: "Title",
|
||
|
value: "Delaware",
|
||
|
});
|
||
|
await verifyHookTrigger(2, "Delaware", request);
|
||
|
await dashboard.grid.editRow({ index: 0, value: "Delaware" });
|
||
|
await dashboard.grid.editRow({ index: 1, value: "Poole" });
|
||
|
await verifyHookTrigger(4, "Poole", request);
|
||
|
await dashboard.grid.deleteRow(1);
|
||
|
await dashboard.grid.deleteRow(0);
|
||
|
await verifyHookTrigger(6, "Delaware", request);
|
||
2 years ago
|
});
|
||
|
});
|