From 42ab034a59643a9d357d8e0d126e4b64c31d38bc Mon Sep 17 00:00:00 2001 From: Takeshi Kimata <117462761+kimatata@users.noreply.github.com> Date: Sat, 13 Apr 2024 13:33:05 +0900 Subject: [PATCH] Implemented test run deletion --- backend/index.js | 4 ++- backend/routes/runs/delete.js | 25 +++++++++++++++++++ backend/seeders/seed.js | 12 ++++----- .../projects/[projectId]/runs/RunsPage.tsx | 3 ++- .../projects/[projectId]/runs/RunsTable.tsx | 2 +- .../[projectId]/runs/[runId]/RunEditor.tsx | 16 ++++++------ frontend/types/run.ts | 2 +- 7 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 backend/routes/runs/delete.js diff --git a/backend/index.js b/backend/index.js index 9c15d3e..1ce917a 100644 --- a/backend/index.js +++ b/backend/index.js @@ -79,11 +79,13 @@ app.use("/attachments", attachmentsDownloadRoute); // "/runs" const runsIndexRoute = require("./routes/runs/index")(sequelize); -const runsShowRoute = require("./routes/cases/show")(sequelize); +const runsShowRoute = require("./routes/runs/show")(sequelize); const runsNewRoute = require("./routes/runs/new")(sequelize); +const runDeleteRoute = require("./routes/runs/delete")(sequelize); app.use("/runs", runsIndexRoute); app.use("/runs", runsShowRoute); app.use("/runs", runsNewRoute); +app.use("/runs", runDeleteRoute); const PORT = process.env.PORT || 3001; app.listen(PORT, () => { diff --git a/backend/routes/runs/delete.js b/backend/routes/runs/delete.js new file mode 100644 index 0000000..a85d5c7 --- /dev/null +++ b/backend/routes/runs/delete.js @@ -0,0 +1,25 @@ +const express = require("express"); +const router = express.Router(); +const defineRun = require("../../models/runs"); +const { DataTypes } = require("sequelize"); + +module.exports = function (sequelize) { + const Run = defineRun(sequelize, DataTypes); + + router.delete("/:runId", async (req, res) => { + const runId = req.params.runId; + try { + const testrun = await Run.findByPk(runId); + if (!testrun) { + return res.status(404).send("Run not found"); + } + await testrun.destroy(); + res.status(204).send(); + } catch (error) { + console.error(error); + res.status(500).send("Internal Server Error"); + } + }); + + return router; +}; diff --git a/backend/seeders/seed.js b/backend/seeders/seed.js index b77a97b..d8ba0af 100644 --- a/backend/seeders/seed.js +++ b/backend/seeders/seed.js @@ -54,8 +54,8 @@ module.exports = { { name: "Run 1", projectId: 1, - configurations: null, - description: null, + configurations: 1, + description: "", state: 1, createdAt: new Date(), updatedAt: new Date(), @@ -63,8 +63,8 @@ module.exports = { { name: "Run 2", projectId: 1, - configurations: null, - description: null, + configurations: 1, + description: "", state: 1, createdAt: new Date(), updatedAt: new Date(), @@ -72,8 +72,8 @@ module.exports = { { name: "Run 3", projectId: 1, - configurations: null, - description: null, + configurations: 1, + description: "", state: 1, createdAt: new Date(), updatedAt: new Date(), diff --git a/frontend/app/projects/[projectId]/runs/RunsPage.tsx b/frontend/app/projects/[projectId]/runs/RunsPage.tsx index f9ca342..b91e51c 100644 --- a/frontend/app/projects/[projectId]/runs/RunsPage.tsx +++ b/frontend/app/projects/[projectId]/runs/RunsPage.tsx @@ -39,7 +39,8 @@ export default function RunsPage({ projectId }: Props) { const onDeleteClick = async (runId: number) => { try { await deleteRun(runId); - setRuns(runs.filter((run) => run.id !== runId)); + const data = await fetchRuns(projectId); + setRuns(data); } catch (error) { console.error("Error deleting run:", error); } diff --git a/frontend/app/projects/[projectId]/runs/RunsTable.tsx b/frontend/app/projects/[projectId]/runs/RunsTable.tsx index 4920f9e..49895ee 100644 --- a/frontend/app/projects/[projectId]/runs/RunsTable.tsx +++ b/frontend/app/projects/[projectId]/runs/RunsTable.tsx @@ -140,7 +140,7 @@ export default function RunsTable({ projectId, runs, onDeleteRun }: Props) { )} - + {(item) => ( {(columnKey) => ( diff --git a/frontend/app/projects/[projectId]/runs/[runId]/RunEditor.tsx b/frontend/app/projects/[projectId]/runs/[runId]/RunEditor.tsx index f22fa8a..88bd966 100644 --- a/frontend/app/projects/[projectId]/runs/[runId]/RunEditor.tsx +++ b/frontend/app/projects/[projectId]/runs/[runId]/RunEditor.tsx @@ -17,7 +17,7 @@ import { fetchRun, updateRun } from "../runsControl"; const defaultTestRun = { id: 0, - title: "", + name: "", configurations: 0, description: "", state: 0, @@ -31,7 +31,7 @@ type Props = { export default function RunEditor({ projectId, runId }: Props) { const [testRun, setTestRun] = useState(defaultTestRun); - const [isTitleInvalid, setIsTitleInvalid] = useState(false); + const [isNameInvalid, setIsNameInvalid] = useState(false); const [isUpdating, setIsUpdating] = useState(false); const router = useRouter(); @@ -62,7 +62,7 @@ export default function RunEditor({ projectId, runId }: Props) { -

{testRun.title}

+

{testRun.name}