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