Implemented test run deletion
This commit is contained in:
@@ -79,11 +79,13 @@ app.use("/attachments", attachmentsDownloadRoute);
|
|||||||
|
|
||||||
// "/runs"
|
// "/runs"
|
||||||
const runsIndexRoute = require("./routes/runs/index")(sequelize);
|
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 runsNewRoute = require("./routes/runs/new")(sequelize);
|
||||||
|
const runDeleteRoute = require("./routes/runs/delete")(sequelize);
|
||||||
app.use("/runs", runsIndexRoute);
|
app.use("/runs", runsIndexRoute);
|
||||||
app.use("/runs", runsShowRoute);
|
app.use("/runs", runsShowRoute);
|
||||||
app.use("/runs", runsNewRoute);
|
app.use("/runs", runsNewRoute);
|
||||||
|
app.use("/runs", runDeleteRoute);
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3001;
|
const PORT = process.env.PORT || 3001;
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
|
|||||||
25
backend/routes/runs/delete.js
Normal file
25
backend/routes/runs/delete.js
Normal file
@@ -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;
|
||||||
|
};
|
||||||
@@ -54,8 +54,8 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
name: "Run 1",
|
name: "Run 1",
|
||||||
projectId: 1,
|
projectId: 1,
|
||||||
configurations: null,
|
configurations: 1,
|
||||||
description: null,
|
description: "",
|
||||||
state: 1,
|
state: 1,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
@@ -63,8 +63,8 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
name: "Run 2",
|
name: "Run 2",
|
||||||
projectId: 1,
|
projectId: 1,
|
||||||
configurations: null,
|
configurations: 1,
|
||||||
description: null,
|
description: "",
|
||||||
state: 1,
|
state: 1,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
@@ -72,8 +72,8 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
name: "Run 3",
|
name: "Run 3",
|
||||||
projectId: 1,
|
projectId: 1,
|
||||||
configurations: null,
|
configurations: 1,
|
||||||
description: null,
|
description: "",
|
||||||
state: 1,
|
state: 1,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ export default function RunsPage({ projectId }: Props) {
|
|||||||
const onDeleteClick = async (runId: number) => {
|
const onDeleteClick = async (runId: number) => {
|
||||||
try {
|
try {
|
||||||
await deleteRun(runId);
|
await deleteRun(runId);
|
||||||
setRuns(runs.filter((run) => run.id !== runId));
|
const data = await fetchRuns(projectId);
|
||||||
|
setRuns(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error deleting run:", error);
|
console.error("Error deleting run:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ export default function RunsTable({ projectId, runs, onDeleteRun }: Props) {
|
|||||||
</TableColumn>
|
</TableColumn>
|
||||||
)}
|
)}
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody emptyContent={"No cases found"} items={sortedItems}>
|
<TableBody emptyContent={"No runs found"} items={sortedItems}>
|
||||||
{(item) => (
|
{(item) => (
|
||||||
<TableRow key={item.id}>
|
<TableRow key={item.id}>
|
||||||
{(columnKey) => (
|
{(columnKey) => (
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { fetchRun, updateRun } from "../runsControl";
|
|||||||
|
|
||||||
const defaultTestRun = {
|
const defaultTestRun = {
|
||||||
id: 0,
|
id: 0,
|
||||||
title: "",
|
name: "",
|
||||||
configurations: 0,
|
configurations: 0,
|
||||||
description: "",
|
description: "",
|
||||||
state: 0,
|
state: 0,
|
||||||
@@ -31,7 +31,7 @@ type Props = {
|
|||||||
|
|
||||||
export default function RunEditor({ projectId, runId }: Props) {
|
export default function RunEditor({ projectId, runId }: Props) {
|
||||||
const [testRun, setTestRun] = useState<RunType>(defaultTestRun);
|
const [testRun, setTestRun] = useState<RunType>(defaultTestRun);
|
||||||
const [isTitleInvalid, setIsTitleInvalid] = useState<boolean>(false);
|
const [isNameInvalid, setIsNameInvalid] = useState<boolean>(false);
|
||||||
const [isUpdating, setIsUpdating] = useState<boolean>(false);
|
const [isUpdating, setIsUpdating] = useState<boolean>(false);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ export default function RunEditor({ projectId, runId }: Props) {
|
|||||||
<ArrowLeft size={16} />
|
<ArrowLeft size={16} />
|
||||||
</Button>
|
</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<h3 className="font-bold ms-2">{testRun.title}</h3>
|
<h3 className="font-bold ms-2">{testRun.name}</h3>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
startContent={<Save size={16} />}
|
startContent={<Save size={16} />}
|
||||||
@@ -84,12 +84,12 @@ export default function RunEditor({ projectId, runId }: Props) {
|
|||||||
size="sm"
|
size="sm"
|
||||||
type="text"
|
type="text"
|
||||||
variant="bordered"
|
variant="bordered"
|
||||||
label="Title"
|
label="Name"
|
||||||
value={testRun.title}
|
value={testRun.name}
|
||||||
isInvalid={isTitleInvalid}
|
isInvalid={isNameInvalid}
|
||||||
errorMessage={isTitleInvalid ? "please enter title" : ""}
|
errorMessage={isNameInvalid ? "please enter name" : ""}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setTestRun({ ...testRun, title: e.target.value });
|
setTestRun({ ...testRun, name: e.target.value });
|
||||||
}}
|
}}
|
||||||
className="mt-3"
|
className="mt-3"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export type RunType = {
|
export type RunType = {
|
||||||
id: number;
|
id: number;
|
||||||
title: string;
|
name: string;
|
||||||
configurations: number;
|
configurations: number;
|
||||||
description: string;
|
description: string;
|
||||||
state: number;
|
state: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user