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"
|
import sdk from "../../../sdk"
|
||||||
|
|
||||||
export function find() {
|
async function getTable(ctx: Ctx) {
|
||||||
throw new Error("Function not implemented.")
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function create(ctx: Ctx<CreateRowActionRequest, RowAction>) {
|
|
||||||
const { tableId } = ctx.params
|
const { tableId } = ctx.params
|
||||||
|
|
||||||
const table = await sdk.tables.getTable(tableId)
|
const table = await sdk.tables.getTable(tableId)
|
||||||
if (!table) {
|
if (!table) {
|
||||||
ctx.throw(404)
|
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
|
// TODO
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,6 @@ describe("/rowsActions", () => {
|
||||||
|
|
||||||
afterAll(setup.afterAll)
|
afterAll(setup.afterAll)
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
table = await config.api.table.save(setup.structures.basicTable())
|
|
||||||
})
|
|
||||||
|
|
||||||
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(
|
||||||
|
@ -43,12 +39,16 @@ describe("/rowsActions", () => {
|
||||||
await config.api.rowAction.save(generator.guid(), {}, { status: 403 })
|
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", () => {
|
describe("create", () => {
|
||||||
unauthorisedTests()
|
unauthorisedTests()
|
||||||
|
|
||||||
it("rejects when using a non-existing table", async () => {
|
it("accepts creating new row actions", async () => {
|
||||||
const res = await config.api.rowAction.save(
|
const res = await config.api.rowAction.save(
|
||||||
table._id!,
|
table._id!,
|
||||||
{},
|
{},
|
||||||
|
@ -57,9 +57,15 @@ describe("/rowsActions", () => {
|
||||||
|
|
||||||
expect(res).toEqual({})
|
expect(res).toEqual({})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it("rejects (404) for a non-existing table", async () => {
|
describe("find", () => {
|
||||||
await config.api.rowAction.save(generator.guid(), {}, { status: 404 })
|
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"
|
import { Expectations, TestAPI } from "./base"
|
||||||
|
|
||||||
export class RowActionAPI extends TestAPI {
|
export class RowActionAPI extends TestAPI {
|
||||||
|
@ -7,11 +11,27 @@ export class RowActionAPI extends TestAPI {
|
||||||
rowAction: CreateRowActionRequest,
|
rowAction: CreateRowActionRequest,
|
||||||
expectations?: Expectations,
|
expectations?: Expectations,
|
||||||
config?: { publicUser?: boolean }
|
config?: { publicUser?: boolean }
|
||||||
): Promise<Row> => {
|
) => {
|
||||||
return await this._post<RowAction>(`/api/tables/${tableId}/actions`, {
|
return await this._post<RowAction>(`/api/tables/${tableId}/actions`, {
|
||||||
body: rowAction,
|
body: rowAction,
|
||||||
expectations,
|
expectations,
|
||||||
...config,
|
...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 CreateRowActionRequest {}
|
||||||
|
|
||||||
export interface RowAction {}
|
export interface RowAction {}
|
||||||
|
|
||||||
|
export interface RowActionsResponse {
|
||||||
|
actions: RowAction[]
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue