Skip to content

Commit

Permalink
Edit item status (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy authored Feb 18, 2024
1 parent 79861e7 commit dfdc962
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/server/controllers/item/update-item-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions src/server/queries/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/server/schema-validator/item-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand All @@ -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,
})
2 changes: 2 additions & 0 deletions src/tests/integration/items.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe("Items", () => {
environment: "new-test-environment",
note: "new-test-note",
base: true,
status: "10",
})
.expect(StatusCode.NoContent)
})
Expand All @@ -87,6 +88,7 @@ describe("Items", () => {
environment: "new-test-environment",
note: "new-test-note",
base: true,
status: "10",
})
.expect(StatusCode.NotFound)
})
Expand Down

0 comments on commit dfdc962

Please sign in to comment.