From dfdc9628fb2d5dde27e992a0fac4b24c2b73ec83 Mon Sep 17 00:00:00 2001 From: Ludek Novy <13610612+ludeknovy@users.noreply.github.com> Date: Sun, 18 Feb 2024 14:48:28 +0100 Subject: [PATCH] Edit item status (#297) --- src/server/controllers/item/update-item-controller.ts | 4 ++-- src/server/queries/items.ts | 6 +++--- src/server/schema-validator/item-schema.ts | 5 +++-- src/tests/integration/items.spec.ts | 2 ++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/server/controllers/item/update-item-controller.ts b/src/server/controllers/item/update-item-controller.ts index f6906fa0..c4e8db59 100644 --- a/src/server/controllers/item/update-item-controller.ts +++ b/src/server/controllers/item/update-item-controller.ts @@ -14,11 +14,11 @@ import { logger } from "../../../logger" export const updateItemController = async (req: Request, res: Response, next: NextFunction) => { const { projectName, scenarioName, itemId } = req.params - const { note, environment, hostname, base, name, resourcesLink } = req.body + const { note, environment, hostname, base, name, resourcesLink, status } = req.body try { await db.query("BEGIN") await db.none(updateTestItemInfo(itemId, scenarioName, projectName, - note, environment, hostname, name, resourcesLink)) + note, environment, hostname, name, resourcesLink, status)) if (base) { await db.none(removeCurrentBaseFlag(scenarioName, projectName)) await db.none(setBaseFlag(itemId, scenarioName, projectName)) diff --git a/src/server/queries/items.ts b/src/server/queries/items.ts index ddcad06e..224f6a58 100644 --- a/src/server/queries/items.ts +++ b/src/server/queries/items.ts @@ -81,15 +81,15 @@ export const saveItemStats = (itemId, stats, overview, sutOverview, errors) => { } export const updateTestItemInfo = (itemId, scenarioName, projectName, note, - environment, hostname, name, resourcesLink) => { + environment, hostname, name, resourcesLink, status) => { return { text: `UPDATE jtl.items as it - SET note = $3, environment = $4, hostname = $6, name = $7, resources_link = $8 + SET note = $3, environment = $4, hostname = $6, name = $7, resources_link = $8, status = COALESCE($9, it.status) FROM jtl.scenario as s WHERE it.id = $1 AND s.project_id = (SELECT id FROM jtl.projects WHERE project_name = $2) AND s.name = $5`, - values: [itemId, projectName, note, environment, scenarioName, hostname, name, resourcesLink], + values: [itemId, projectName, note, environment, scenarioName, hostname, name, resourcesLink, status], } } diff --git a/src/server/schema-validator/item-schema.ts b/src/server/schema-validator/item-schema.ts index 741dd7c1..870771b8 100644 --- a/src/server/schema-validator/item-schema.ts +++ b/src/server/schema-validator/item-schema.ts @@ -15,7 +15,7 @@ const hostname = Joi.string().max(HOSTNAME_MAX_LENGTH).allow("").allow(null) const note = Joi.string().max(NOTE_MAX_LENGTH).allow("").allow(null) const itemId = Joi.string().uuid().required() const resourcesLink = Joi.string().max(RESOURCES_LINK_MAX_LENGTH).allow("").allow(null) - +const status = Joi.string().regex(/^(10|[0-3])$/) export const labelParamSchema = { projectName, @@ -49,6 +49,7 @@ export const updateItemBodySchema = Joi.object().keys({ environment, name: Joi.string().max(TEST_NAME_MAX_LENGTH).allow("").allow(null), resourcesLink, + status, }) export const newAsyncItemStartBodySchema = Joi.object().keys({ @@ -70,5 +71,5 @@ export const upsertUserItemChartSettings = Joi.array().items(Joi.object().keys({ })).required() export const stopItemAsyncBodySchema = Joi.object().keys({ - status: Joi.string().regex(/^(10|[0-3])$/), + status, }) diff --git a/src/tests/integration/items.spec.ts b/src/tests/integration/items.spec.ts index 5936c735..85ea6fa0 100644 --- a/src/tests/integration/items.spec.ts +++ b/src/tests/integration/items.spec.ts @@ -74,6 +74,7 @@ describe("Items", () => { environment: "new-test-environment", note: "new-test-note", base: true, + status: "10", }) .expect(StatusCode.NoContent) }) @@ -87,6 +88,7 @@ describe("Items", () => { environment: "new-test-environment", note: "new-test-note", base: true, + status: "10", }) .expect(StatusCode.NotFound) })