Trims names
This commit is contained in:
parent
7fb13b757b
commit
c51d2cd431
|
@ -95,6 +95,31 @@ describe("/rowsActions", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("trims row action names", async () => {
|
||||||
|
const name = " action name "
|
||||||
|
const res = await createRowAction(
|
||||||
|
tableId,
|
||||||
|
{ name },
|
||||||
|
{
|
||||||
|
status: 201,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(res).toEqual({
|
||||||
|
id: expect.stringMatching(/^row_action_\w+/),
|
||||||
|
tableId: tableId,
|
||||||
|
name: "action name",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(await config.api.rowAction.find(tableId)).toEqual({
|
||||||
|
actions: {
|
||||||
|
[res.id]: expect.objectContaining({
|
||||||
|
name: "action name",
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it("can create multiple row actions for the same table", async () => {
|
it("can create multiple row actions for the same table", async () => {
|
||||||
const rowActions = createRowActionRequests(3)
|
const rowActions = createRowActionRequests(3)
|
||||||
const responses: RowActionResponse[] = []
|
const responses: RowActionResponse[] = []
|
||||||
|
@ -224,6 +249,33 @@ describe("/rowsActions", () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("trims row action names", async () => {
|
||||||
|
const rowAction = await createRowAction(
|
||||||
|
tableId,
|
||||||
|
createRowActionRequest(),
|
||||||
|
{
|
||||||
|
status: 201,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const res = await config.api.rowAction.update(tableId, rowAction.id, {
|
||||||
|
...rowAction,
|
||||||
|
name: " action name ",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(res).toEqual(expect.objectContaining({ name: "action name" }))
|
||||||
|
|
||||||
|
expect(await config.api.rowAction.find(tableId)).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
actions: expect.objectContaining({
|
||||||
|
[rowAction.id]: expect.objectContaining({
|
||||||
|
name: "action name",
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("throws Bad Request when trying to update by a non-existing id", async () => {
|
it("throws Bad Request when trying to update by a non-existing id", async () => {
|
||||||
await createRowAction(tableId, createRowActionRequest())
|
await createRowAction(tableId, createRowActionRequest())
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
export async function create(tableId: string, rowAction: { name: string }) {
|
export async function create(tableId: string, rowAction: { name: string }) {
|
||||||
|
const action = { name: rowAction.name.trim() }
|
||||||
|
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
const rowActionsId = generateRowActionsID(tableId)
|
const rowActionsId = generateRowActionsID(tableId)
|
||||||
let doc: TableRowActions
|
let doc: TableRowActions
|
||||||
|
@ -22,12 +24,12 @@ export async function create(tableId: string, rowAction: { name: string }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const newId = `${VirtualDocumentType.ROW_ACTION}${SEPARATOR}${utils.newid()}`
|
const newId = `${VirtualDocumentType.ROW_ACTION}${SEPARATOR}${utils.newid()}`
|
||||||
doc.actions[newId] = rowAction
|
doc.actions[newId] = action
|
||||||
await db.put(doc)
|
await db.put(doc)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: newId,
|
id: newId,
|
||||||
...rowAction,
|
...action,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +51,7 @@ export async function update(
|
||||||
rowActionId: string,
|
rowActionId: string,
|
||||||
rowAction: { name: string }
|
rowAction: { name: string }
|
||||||
) {
|
) {
|
||||||
|
const action = { name: rowAction.name.trim() }
|
||||||
const actionsDoc = await get(tableId)
|
const actionsDoc = await get(tableId)
|
||||||
|
|
||||||
if (!actionsDoc.actions[rowActionId]) {
|
if (!actionsDoc.actions[rowActionId]) {
|
||||||
|
@ -57,14 +60,14 @@ export async function update(
|
||||||
400
|
400
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
actionsDoc.actions[rowActionId] = rowAction
|
actionsDoc.actions[rowActionId] = action
|
||||||
|
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
await db.put(actionsDoc)
|
await db.put(actionsDoc)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: rowActionId,
|
id: rowActionId,
|
||||||
...rowAction,
|
...action,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue