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 {
CreateRowActionRequest,
Ctx,
RowAction,
RowActionsResponse,
} from "@budibase/types"
import sdk from "../../../sdk"
@ -20,15 +19,18 @@ export async function find(ctx: Ctx<void, RowActionsResponse>) {
// 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)
// TODO
ctx.status = 201
ctx.status = 204
}
export function update() {

View file

@ -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: [] })
})
})
})

View file

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