Basic get
This commit is contained in:
parent
de2938799b
commit
0c2024bf6a
|
@ -1,17 +1,30 @@
|
|||
import { CreateRowActionRequest, Ctx, RowAction } from "@budibase/types"
|
||||
import {
|
||||
CreateRowActionRequest,
|
||||
Ctx,
|
||||
RowAction,
|
||||
RowActionsResponse,
|
||||
} from "@budibase/types"
|
||||
import sdk from "../../../sdk"
|
||||
|
||||
export function find() {
|
||||
throw new Error("Function not implemented.")
|
||||
}
|
||||
|
||||
export async function create(ctx: Ctx<CreateRowActionRequest, RowAction>) {
|
||||
async function getTable(ctx: Ctx) {
|
||||
const { tableId } = ctx.params
|
||||
|
||||
const table = await sdk.tables.getTable(tableId)
|
||||
if (!table) {
|
||||
ctx.throw(404)
|
||||
}
|
||||
return table
|
||||
}
|
||||
|
||||
export async function find(ctx: Ctx<void, RowActionsResponse>) {
|
||||
const table = await getTable(ctx)
|
||||
|
||||
// TODO
|
||||
|
||||
ctx.body = { actions: [] }
|
||||
}
|
||||
|
||||
export async function create(ctx: Ctx<CreateRowActionRequest, RowAction>) {
|
||||
const table = await getTable(ctx)
|
||||
|
||||
// TODO
|
||||
|
||||
|
|
|
@ -16,10 +16,6 @@ describe("/rowsActions", () => {
|
|||
|
||||
afterAll(setup.afterAll)
|
||||
|
||||
beforeAll(async () => {
|
||||
table = await config.api.table.save(setup.structures.basicTable())
|
||||
})
|
||||
|
||||
function unauthorisedTests() {
|
||||
it("returns unauthorised (401) for unauthenticated requests", async () => {
|
||||
await config.api.rowAction.save(
|
||||
|
@ -43,12 +39,16 @@ describe("/rowsActions", () => {
|
|||
await config.api.rowAction.save(generator.guid(), {}, { status: 403 })
|
||||
})
|
||||
})
|
||||
|
||||
it("rejects (404) for a non-existing table", async () => {
|
||||
await config.api.rowAction.save(generator.guid(), {}, { status: 404 })
|
||||
})
|
||||
}
|
||||
|
||||
describe("create", () => {
|
||||
unauthorisedTests()
|
||||
|
||||
it("rejects when using a non-existing table", async () => {
|
||||
it("accepts creating new row actions", async () => {
|
||||
const res = await config.api.rowAction.save(
|
||||
table._id!,
|
||||
{},
|
||||
|
@ -57,9 +57,15 @@ describe("/rowsActions", () => {
|
|||
|
||||
expect(res).toEqual({})
|
||||
})
|
||||
})
|
||||
|
||||
it("rejects (404) for a non-existing table", async () => {
|
||||
await config.api.rowAction.save(generator.guid(), {}, { status: 404 })
|
||||
describe("find", () => {
|
||||
unauthorisedTests()
|
||||
|
||||
it("returns empty for tables without row actions", async () => {
|
||||
const res = await config.api.rowAction.find(table._id!, {})
|
||||
|
||||
expect(res).toEqual({ actions: [] })
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
import { CreateRowActionRequest, Row, RowAction } from "@budibase/types"
|
||||
import {
|
||||
CreateRowActionRequest,
|
||||
RowAction,
|
||||
RowActionsResponse,
|
||||
} from "@budibase/types"
|
||||
import { Expectations, TestAPI } from "./base"
|
||||
|
||||
export class RowActionAPI extends TestAPI {
|
||||
|
@ -7,11 +11,27 @@ export class RowActionAPI extends TestAPI {
|
|||
rowAction: CreateRowActionRequest,
|
||||
expectations?: Expectations,
|
||||
config?: { publicUser?: boolean }
|
||||
): Promise<Row> => {
|
||||
) => {
|
||||
return await this._post<RowAction>(`/api/tables/${tableId}/actions`, {
|
||||
body: rowAction,
|
||||
expectations,
|
||||
...config,
|
||||
})
|
||||
}
|
||||
|
||||
find = async (
|
||||
tableId: string,
|
||||
rowAction: CreateRowActionRequest,
|
||||
expectations?: Expectations,
|
||||
config?: { publicUser?: boolean }
|
||||
) => {
|
||||
return await this._get<RowActionsResponse>(
|
||||
`/api/tables/${tableId}/actions`,
|
||||
{
|
||||
body: rowAction,
|
||||
expectations,
|
||||
...config,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
export interface CreateRowActionRequest {}
|
||||
|
||||
export interface RowAction {}
|
||||
|
||||
export interface RowActionsResponse {
|
||||
actions: RowAction[]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue