mirror of https://github.com/nocodb/nocodb
Raju Udava
2 years ago
committed by
Muhammed Mustafa
5 changed files with 1323 additions and 34 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,64 @@ |
|||||||
|
// https://glebbahmutov.com/blog/restart-server/
|
||||||
|
|
||||||
|
// const { express } = require("express");
|
||||||
|
// const { bodyParser } = require("body-parser");
|
||||||
|
|
||||||
|
import express from "express"; |
||||||
|
import bodyParser from "body-parser"; |
||||||
|
|
||||||
|
let request = []; |
||||||
|
|
||||||
|
async function makeServer() { |
||||||
|
const app = express(); |
||||||
|
app.use(bodyParser.json()); |
||||||
|
|
||||||
|
app.get("/hook/all", (req, res) => { |
||||||
|
// console.log(request)
|
||||||
|
res.json(request); |
||||||
|
}); |
||||||
|
app.get("/hook/last", (req, res) => { |
||||||
|
if (request.length) { |
||||||
|
// console.log(request[request.length - 1])
|
||||||
|
res.json(request[request.length - 1]); |
||||||
|
} |
||||||
|
}); |
||||||
|
app.get("/hook/count", (req, res) => { |
||||||
|
// console.log(request.length)
|
||||||
|
res.json(request.length); |
||||||
|
}); |
||||||
|
app.get("/hook/clear", (req, res) => { |
||||||
|
request = []; |
||||||
|
res.status(200).end(); |
||||||
|
}); |
||||||
|
|
||||||
|
app.post("/hook", (req, res) => { |
||||||
|
request.push(req.body); |
||||||
|
// console.log("/hook :: ", req.body) // Call your action on the request here
|
||||||
|
res.status(200).end(); // Responding is important
|
||||||
|
}); |
||||||
|
|
||||||
|
app.post("/stop", (req, res) => { |
||||||
|
process.exit(); |
||||||
|
}); |
||||||
|
|
||||||
|
const port = 9090; |
||||||
|
|
||||||
|
return new Promise((resolve) => { |
||||||
|
const server = app.listen(port, function () { |
||||||
|
const port = server.address().port; |
||||||
|
console.log("Example app listening at port %d", port); |
||||||
|
|
||||||
|
// close the server
|
||||||
|
const close = () => { |
||||||
|
return new Promise((resolve) => { |
||||||
|
console.log("closing server"); |
||||||
|
server.close(resolve); |
||||||
|
}); |
||||||
|
}; |
||||||
|
|
||||||
|
resolve({ server, port, close }); |
||||||
|
}); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
export default makeServer; |
@ -1,32 +1,242 @@ |
|||||||
import { test } from "@playwright/test"; |
import { expect, test } from "@playwright/test"; |
||||||
import { DashboardPage } from "../pages/Dashboard"; |
import { DashboardPage } from "../pages/Dashboard"; |
||||||
import setup from "../setup"; |
import setup from "../setup"; |
||||||
import { ToolbarPage } from "../pages/Dashboard/common/Toolbar"; |
import { ToolbarPage } from "../pages/Dashboard/common/Toolbar"; |
||||||
|
import makeServer from "../setup/server"; |
||||||
|
import { WebhookFormPage } from "../pages/Dashboard/WebhookForm"; |
||||||
|
|
||||||
test.describe.skip("Webhook", () => { |
let hookPath = "http://localhost:9090/hook"; |
||||||
let dashboard: DashboardPage, toolbar: ToolbarPage; |
|
||||||
|
// 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"); |
||||||
|
expect(await response.json()).toBe(0); |
||||||
|
} |
||||||
|
|
||||||
|
async function verifyHookTrigger(count: number, value: string, request) { |
||||||
|
let response = await request.get(hookPath + "/count"); |
||||||
|
expect(await response.json()).toBe(count); |
||||||
|
|
||||||
|
if (count) { |
||||||
|
response = await request.get(hookPath + "/last"); |
||||||
|
console.log(await response.json()); |
||||||
|
expect((await response.json()).Title).toBe(value); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
test.describe("Webhook", () => { |
||||||
|
let dashboard: DashboardPage, toolbar: ToolbarPage, webhook: WebhookFormPage; |
||||||
let context: any; |
let context: any; |
||||||
|
|
||||||
|
test.beforeAll(async () => { |
||||||
|
// start a server locally for webhook tests
|
||||||
|
await makeServer(); |
||||||
|
}); |
||||||
|
|
||||||
test.beforeEach(async ({ page }) => { |
test.beforeEach(async ({ page }) => { |
||||||
context = await setup({ page }); |
context = await setup({ page }); |
||||||
dashboard = new DashboardPage(page, context.project); |
dashboard = new DashboardPage(page, context.project); |
||||||
toolbar = dashboard.grid.toolbar; |
toolbar = dashboard.grid.toolbar; |
||||||
|
webhook = dashboard.webhookForm; |
||||||
}); |
}); |
||||||
|
|
||||||
test("CRUD", async () => { |
test("CRUD", async ({ request }) => { |
||||||
// close 'Team & Auth' tab
|
// close 'Team & Auth' tab
|
||||||
await dashboard.closeTab({ title: "Team & Auth" }); |
await dashboard.closeTab({ title: "Team & Auth" }); |
||||||
await dashboard.treeView.createTable({ title: "Test" }); |
await dashboard.treeView.createTable({ title: "Test" }); |
||||||
|
|
||||||
await toolbar.clickActions(); |
// after insert hook
|
||||||
await toolbar.actions.click("Webhooks"); |
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); |
||||||
|
}); |
||||||
|
|
||||||
await dashboard.webhookForm.create({ |
test("Conditional webhooks", async ({ request }) => { |
||||||
title: "Test", |
// close 'Team & Auth' tab
|
||||||
url: "https://example.com", |
await dashboard.closeTab({ title: "Team & Auth" }); |
||||||
|
await dashboard.treeView.createTable({ title: "Test" }); |
||||||
|
|
||||||
|
// after insert hook
|
||||||
|
await webhook.create({ |
||||||
|
title: "hook-1", |
||||||
event: "After Insert", |
event: "After Insert", |
||||||
}); |
}); |
||||||
|
// 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, |
||||||
|
}); |
||||||
|
|
||||||
await dashboard.webhookForm.addCondition(); |
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); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
Loading…
Reference in new issue