1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00

More types

This commit is contained in:
Adria Navarro 2024-07-10 15:41:55 +02:00
parent 0c2024bf6a
commit bf161d9d93
4 changed files with 39 additions and 19 deletions

View file

@ -1,7 +1,6 @@
import { import {
CreateRowActionRequest, CreateRowActionRequest,
Ctx, Ctx,
RowAction,
RowActionsResponse, RowActionsResponse,
} from "@budibase/types" } from "@budibase/types"
import sdk from "../../../sdk" import sdk from "../../../sdk"
@ -20,15 +19,18 @@ export async function find(ctx: Ctx<void, RowActionsResponse>) {
// TODO // TODO
ctx.body = { actions: [] } ctx.body = {
tableId: table._id!,
actions: [],
}
} }
export async function create(ctx: Ctx<CreateRowActionRequest, RowAction>) { export async function create(ctx: Ctx<CreateRowActionRequest, void>) {
const table = await getTable(ctx) const table = await getTable(ctx)
// TODO // TODO
ctx.status = 201 ctx.status = 204
} }
export function update() { export function update() {

View file

@ -1,5 +1,5 @@
import _ from "lodash" import _ from "lodash"
import { Table } from "@budibase/types" import { CreateRowActionRequest, Table } from "@budibase/types"
import * as setup from "./utilities" import * as setup from "./utilities"
import { generator } from "@budibase/backend-core/tests" import { generator } from "@budibase/backend-core/tests"
@ -16,11 +16,17 @@ describe("/rowsActions", () => {
afterAll(setup.afterAll) afterAll(setup.afterAll)
function createRowActionRequest(): CreateRowActionRequest {
return {
name: generator.word(),
}
}
function unauthorisedTests() { function unauthorisedTests() {
it("returns unauthorised (401) for unauthenticated requests", async () => { it("returns unauthorised (401) for unauthenticated requests", async () => {
await config.api.rowAction.save( await config.api.rowAction.save(
table._id!, table._id!,
{}, createRowActionRequest(),
{ {
status: 401, status: 401,
body: { body: {
@ -36,12 +42,20 @@ describe("/rowsActions", () => {
builder: {}, builder: {},
}) })
await config.withUser(user, async () => { 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 () => { 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() unauthorisedTests()
it("accepts creating new row actions", async () => { it("accepts creating new row actions", async () => {
const res = await config.api.rowAction.save( const rowAction = createRowActionRequest()
table._id!,
{}, const res = await config.api.rowAction.save(table._id!, rowAction, {
{ status: 201 } status: 204,
) })
expect(res).toEqual({}) expect(res).toEqual({})
}) })
@ -63,9 +77,10 @@ describe("/rowsActions", () => {
unauthorisedTests() unauthorisedTests()
it("returns empty for tables without row actions", async () => { 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: [] })
}) })
}) })
}) })

View file

@ -21,14 +21,12 @@ export class RowActionAPI extends TestAPI {
find = async ( find = async (
tableId: string, tableId: string,
rowAction: CreateRowActionRequest,
expectations?: Expectations, expectations?: Expectations,
config?: { publicUser?: boolean } config?: { publicUser?: boolean }
) => { ) => {
return await this._get<RowActionsResponse>( return await this._get<RowActionsResponse>(
`/api/tables/${tableId}/actions`, `/api/tables/${tableId}/actions`,
{ {
body: rowAction,
expectations, expectations,
...config, ...config,
} }

View file

@ -1,7 +1,12 @@
export interface CreateRowActionRequest {} export interface CreateRowActionRequest {
name: string
}
export interface RowAction {} interface RowAction {
name: string
}
export interface RowActionsResponse { export interface RowActionsResponse {
tableId: string
actions: RowAction[] actions: RowAction[]
} }