Check ui path vs body

This commit is contained in:
Adria Navarro 2023-07-25 19:46:46 +02:00
parent 783e8a5b08
commit b2e0384f8a
2 changed files with 19 additions and 0 deletions

View File

@ -24,6 +24,10 @@ export async function update(ctx: Ctx<UpdateViewRequest, ViewResponse>) {
ctx.throw(400, "Only views V2 can be updated")
}
if (ctx.params.viewId !== view.id) {
ctx.throw(400, "View id does not match between the body and the uri path")
}
const { tableId } = view
const result = await sdk.views.update(tableId, view)

View File

@ -187,6 +187,21 @@ describe("/v2/views", () => {
}
)
})
it("cannot update the a view with unmatching ids between url and body", async () => {
const anotherView = await config.api.viewV2.create()
const result = await config
.request!.put(`/api/v2/views/${anotherView.id}`)
.send(view)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(400)
expect(result.body).toEqual({
message: "View id does not match between the body and the uri path",
status: 400,
})
})
})
describe("delete", () => {