diff --git a/packages/server/src/api/controllers/rowAction/crud.ts b/packages/server/src/api/controllers/rowAction/crud.ts index 1e6b4f4671..83b4215f35 100644 --- a/packages/server/src/api/controllers/rowAction/crud.ts +++ b/packages/server/src/api/controllers/rowAction/crud.ts @@ -1,7 +1,6 @@ import { CreateRowActionRequest, Ctx, - RowAction, RowActionsResponse, } from "@budibase/types" import sdk from "../../../sdk" @@ -20,15 +19,18 @@ export async function find(ctx: Ctx) { // TODO - ctx.body = { actions: [] } + ctx.body = { + tableId: table._id!, + actions: [], + } } -export async function create(ctx: Ctx) { +export async function create(ctx: Ctx) { const table = await getTable(ctx) // TODO - ctx.status = 201 + ctx.status = 204 } export function update() { diff --git a/packages/server/src/api/routes/tests/rowAction.spec.ts b/packages/server/src/api/routes/tests/rowAction.spec.ts index edf6d64393..ac0bff4781 100644 --- a/packages/server/src/api/routes/tests/rowAction.spec.ts +++ b/packages/server/src/api/routes/tests/rowAction.spec.ts @@ -1,5 +1,5 @@ import _ from "lodash" -import { Table } from "@budibase/types" +import { CreateRowActionRequest, Table } from "@budibase/types" import * as setup from "./utilities" import { generator } from "@budibase/backend-core/tests" @@ -16,11 +16,17 @@ describe("/rowsActions", () => { afterAll(setup.afterAll) + function createRowActionRequest(): CreateRowActionRequest { + return { + name: generator.word(), + } + } + function unauthorisedTests() { it("returns unauthorised (401) for unauthenticated requests", async () => { await config.api.rowAction.save( table._id!, - {}, + createRowActionRequest(), { status: 401, body: { @@ -36,12 +42,20 @@ describe("/rowsActions", () => { builder: {}, }) await config.withUser(user, async () => { - await config.api.rowAction.save(generator.guid(), {}, { status: 403 }) + await config.api.rowAction.save( + generator.guid(), + createRowActionRequest(), + { status: 403 } + ) }) }) it("rejects (404) for a non-existing table", async () => { - await config.api.rowAction.save(generator.guid(), {}, { status: 404 }) + await config.api.rowAction.save( + generator.guid(), + createRowActionRequest(), + { status: 404 } + ) }) } @@ -49,11 +63,11 @@ describe("/rowsActions", () => { unauthorisedTests() it("accepts creating new row actions", async () => { - const res = await config.api.rowAction.save( - table._id!, - {}, - { status: 201 } - ) + const rowAction = createRowActionRequest() + + const res = await config.api.rowAction.save(table._id!, rowAction, { + status: 204, + }) expect(res).toEqual({}) }) @@ -63,9 +77,10 @@ describe("/rowsActions", () => { unauthorisedTests() it("returns empty for tables without row actions", async () => { - const res = await config.api.rowAction.find(table._id!, {}) + const tableId = table._id! + const res = await config.api.rowAction.find(tableId) - expect(res).toEqual({ actions: [] }) + expect(res).toEqual({ tableId, actions: [] }) }) }) }) diff --git a/packages/server/src/tests/utilities/api/rowAction.ts b/packages/server/src/tests/utilities/api/rowAction.ts index 7a85db21e9..a78633681e 100644 --- a/packages/server/src/tests/utilities/api/rowAction.ts +++ b/packages/server/src/tests/utilities/api/rowAction.ts @@ -21,14 +21,12 @@ export class RowActionAPI extends TestAPI { find = async ( tableId: string, - rowAction: CreateRowActionRequest, expectations?: Expectations, config?: { publicUser?: boolean } ) => { return await this._get( `/api/tables/${tableId}/actions`, { - body: rowAction, expectations, ...config, } diff --git a/packages/types/src/api/web/app/rowAction.ts b/packages/types/src/api/web/app/rowAction.ts index d1935a5b51..fceb606699 100644 --- a/packages/types/src/api/web/app/rowAction.ts +++ b/packages/types/src/api/web/app/rowAction.ts @@ -1,7 +1,12 @@ -export interface CreateRowActionRequest {} +export interface CreateRowActionRequest { + name: string +} -export interface RowAction {} +interface RowAction { + name: string +} export interface RowActionsResponse { + tableId: string actions: RowAction[] }