Return automationid from row action api
This commit is contained in:
parent
4a8f15995c
commit
eaa38c5c2d
|
@ -31,7 +31,12 @@ export async function find(ctx: Ctx<void, RowActionsResponse>) {
|
|||
actions: Object.entries(actions).reduce<Record<string, RowActionResponse>>(
|
||||
(acc, [key, action]) => ({
|
||||
...acc,
|
||||
[key]: { id: key, tableId: table._id!, ...action },
|
||||
[key]: {
|
||||
id: key,
|
||||
tableId: table._id!,
|
||||
name: action.name,
|
||||
automationId: action.automationId,
|
||||
},
|
||||
}),
|
||||
{}
|
||||
),
|
||||
|
@ -50,7 +55,9 @@ export async function create(
|
|||
|
||||
ctx.body = {
|
||||
tableId: table._id!,
|
||||
...createdAction,
|
||||
id: createdAction.id,
|
||||
name: createdAction.name,
|
||||
automationId: createdAction.automationId,
|
||||
}
|
||||
ctx.status = 201
|
||||
}
|
||||
|
@ -61,13 +68,15 @@ export async function update(
|
|||
const table = await getTable(ctx)
|
||||
const { actionId } = ctx.params
|
||||
|
||||
const actions = await sdk.rowActions.update(table._id!, actionId, {
|
||||
const action = await sdk.rowActions.update(table._id!, actionId, {
|
||||
name: ctx.request.body.name,
|
||||
})
|
||||
|
||||
ctx.body = {
|
||||
tableId: table._id!,
|
||||
...actions,
|
||||
id: action.id,
|
||||
name: action.name,
|
||||
automationId: action.automationId,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,9 @@ import {
|
|||
import * as setup from "./utilities"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
|
||||
const expectAutomationId = () =>
|
||||
expect.stringMatching(`^${DocumentType.AUTOMATION}_.+`)
|
||||
|
||||
describe("/rowsActions", () => {
|
||||
const config = setup.getConfig()
|
||||
|
||||
|
@ -83,20 +86,19 @@ describe("/rowsActions", () => {
|
|||
})
|
||||
|
||||
expect(res).toEqual({
|
||||
name: rowAction.name,
|
||||
id: expect.stringMatching(/^row_action_\w+/),
|
||||
tableId: tableId,
|
||||
...rowAction,
|
||||
automationId: expectAutomationId(),
|
||||
})
|
||||
|
||||
expect(await config.api.rowAction.find(tableId)).toEqual({
|
||||
actions: {
|
||||
[res.id]: {
|
||||
...rowAction,
|
||||
name: rowAction.name,
|
||||
id: res.id,
|
||||
tableId: tableId,
|
||||
automationId: expect.stringMatching(
|
||||
`^${DocumentType.AUTOMATION}_.+`
|
||||
),
|
||||
automationId: expectAutomationId(),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
@ -104,19 +106,13 @@ describe("/rowsActions", () => {
|
|||
|
||||
it("trims row action names", async () => {
|
||||
const name = " action name "
|
||||
const res = await createRowAction(
|
||||
tableId,
|
||||
{ name },
|
||||
{
|
||||
status: 201,
|
||||
}
|
||||
)
|
||||
const res = await createRowAction(tableId, { name }, { status: 201 })
|
||||
|
||||
expect(res).toEqual({
|
||||
id: expect.stringMatching(/^row_action_\w+/),
|
||||
tableId: tableId,
|
||||
expect(res).toEqual(
|
||||
expect.objectContaining({
|
||||
name: "action name",
|
||||
})
|
||||
)
|
||||
|
||||
expect(await config.api.rowAction.find(tableId)).toEqual({
|
||||
actions: {
|
||||
|
@ -137,19 +133,19 @@ describe("/rowsActions", () => {
|
|||
expect(await config.api.rowAction.find(tableId)).toEqual({
|
||||
actions: {
|
||||
[responses[0].id]: {
|
||||
...rowActions[0],
|
||||
name: rowActions[0].name,
|
||||
id: responses[0].id,
|
||||
tableId,
|
||||
automationId: expect.any(String),
|
||||
},
|
||||
[responses[1].id]: {
|
||||
...rowActions[1],
|
||||
name: rowActions[1].name,
|
||||
id: responses[1].id,
|
||||
tableId,
|
||||
automationId: expect.any(String),
|
||||
},
|
||||
[responses[2].id]: {
|
||||
...rowActions[2],
|
||||
name: rowActions[2].name,
|
||||
id: responses[2].id,
|
||||
tableId,
|
||||
automationId: expect.any(String),
|
||||
|
@ -174,7 +170,7 @@ describe("/rowsActions", () => {
|
|||
it("ignores not valid row action data", async () => {
|
||||
const rowAction = createRowActionRequest()
|
||||
const dirtyRowAction = {
|
||||
...rowAction,
|
||||
name: rowAction.name,
|
||||
id: generator.guid(),
|
||||
valueToIgnore: generator.string(),
|
||||
}
|
||||
|
@ -183,17 +179,18 @@ describe("/rowsActions", () => {
|
|||
})
|
||||
|
||||
expect(res).toEqual({
|
||||
name: rowAction.name,
|
||||
id: expect.any(String),
|
||||
tableId,
|
||||
...rowAction,
|
||||
automationId: expectAutomationId(),
|
||||
})
|
||||
|
||||
expect(await config.api.rowAction.find(tableId)).toEqual({
|
||||
actions: {
|
||||
[res.id]: {
|
||||
name: rowAction.name,
|
||||
id: res.id,
|
||||
tableId: tableId,
|
||||
...rowAction,
|
||||
automationId: expect.any(String),
|
||||
},
|
||||
},
|
||||
|
@ -287,7 +284,6 @@ describe("/rowsActions", () => {
|
|||
const updatedName = generator.string()
|
||||
|
||||
const res = await config.api.rowAction.update(tableId, actionId, {
|
||||
...actionData,
|
||||
name: updatedName,
|
||||
})
|
||||
|
||||
|
@ -295,14 +291,17 @@ describe("/rowsActions", () => {
|
|||
id: actionId,
|
||||
tableId,
|
||||
name: updatedName,
|
||||
automationId: actionData.automationId,
|
||||
})
|
||||
|
||||
expect(await config.api.rowAction.find(tableId)).toEqual(
|
||||
expect.objectContaining({
|
||||
actions: expect.objectContaining({
|
||||
[actionId]: {
|
||||
...actionData,
|
||||
name: updatedName,
|
||||
id: actionData.id,
|
||||
tableId: actionData.tableId,
|
||||
automationId: actionData.automationId,
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
@ -319,7 +318,6 @@ describe("/rowsActions", () => {
|
|||
)
|
||||
|
||||
const res = await config.api.rowAction.update(tableId, rowAction.id, {
|
||||
...rowAction,
|
||||
name: " action name ",
|
||||
})
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ export async function create(tableId: string, rowAction: { name: string }) {
|
|||
|
||||
return {
|
||||
id: newId,
|
||||
...action,
|
||||
...doc.actions[newId],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,20 +135,24 @@ export async function update(
|
|||
|
||||
return {
|
||||
id: rowActionId,
|
||||
...action,
|
||||
...actionsDoc.actions[rowActionId],
|
||||
}
|
||||
}
|
||||
|
||||
export async function remove(tableId: string, rowActionId: string) {
|
||||
const actionsDoc = await get(tableId)
|
||||
|
||||
if (!actionsDoc.actions[rowActionId]) {
|
||||
const rowAction = actionsDoc.actions[rowActionId]
|
||||
if (!rowAction) {
|
||||
throw new HTTPError(
|
||||
`Row action '${rowActionId}' not found in '${tableId}'`,
|
||||
400
|
||||
)
|
||||
}
|
||||
|
||||
const { automationId } = rowAction
|
||||
const automation = await automations.get(automationId)
|
||||
await automations.remove(automation._id, automation._rev)
|
||||
delete actionsDoc.actions[rowActionId]
|
||||
|
||||
const db = context.getAppDB()
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import { Automation } from "@budibase/types"
|
||||
import { Expectations, TestAPI } from "./base"
|
||||
|
||||
export class AutomationAPI extends TestAPI {
|
||||
get = async (
|
||||
automationId: string,
|
||||
expectations?: Expectations
|
||||
): Promise<Automation> => {
|
||||
const result = await this._get<Automation>(
|
||||
`/api/automations/${automationId}`,
|
||||
{
|
||||
expectations,
|
||||
}
|
||||
)
|
||||
return result
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ import { QueryAPI } from "./query"
|
|||
import { RoleAPI } from "./role"
|
||||
import { TemplateAPI } from "./template"
|
||||
import { RowActionAPI } from "./rowAction"
|
||||
import { AutomationAPI } from "./automation"
|
||||
|
||||
export default class API {
|
||||
table: TableAPI
|
||||
|
@ -31,6 +32,7 @@ export default class API {
|
|||
roles: RoleAPI
|
||||
templates: TemplateAPI
|
||||
rowAction: RowActionAPI
|
||||
automation: AutomationAPI
|
||||
|
||||
constructor(config: TestConfiguration) {
|
||||
this.table = new TableAPI(config)
|
||||
|
@ -48,5 +50,6 @@ export default class API {
|
|||
this.roles = new RoleAPI(config)
|
||||
this.templates = new TemplateAPI(config)
|
||||
this.rowAction = new RowActionAPI(config)
|
||||
this.automation = new AutomationAPI(config)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ export interface UpdateRowActionRequest extends RowActionData {}
|
|||
export interface RowActionResponse extends RowActionData {
|
||||
id: string
|
||||
tableId: string
|
||||
automationId: string
|
||||
}
|
||||
|
||||
export interface RowActionsResponse {
|
||||
|
|
Loading…
Reference in New Issue