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

Initial test

This commit is contained in:
Adria Navarro 2024-07-10 13:24:25 +02:00
parent 38718968b0
commit de2938799b
3 changed files with 85 additions and 0 deletions

View file

@ -0,0 +1,65 @@
import _ from "lodash"
import { Table } from "@budibase/types"
import * as setup from "./utilities"
import { generator } from "@budibase/backend-core/tests"
describe("/rowsActions", () => {
const config = setup.getConfig()
let table: Table
beforeAll(async () => {
await config.init()
table = await config.api.table.save(setup.structures.basicTable())
})
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(
table._id!,
{},
{
status: 401,
body: {
message: "Session not authenticated",
},
},
{ publicUser: true }
)
})
it("returns forbidden (403) for non-builder users", async () => {
const user = await config.createUser({
builder: {},
})
await config.withUser(user, async () => {
await config.api.rowAction.save(generator.guid(), {}, { status: 403 })
})
})
}
describe("create", () => {
unauthorisedTests()
it("rejects when using a non-existing table", async () => {
const res = await config.api.rowAction.save(
table._id!,
{},
{ status: 201 }
)
expect(res).toEqual({})
})
it("rejects (404) for a non-existing table", async () => {
await config.api.rowAction.save(generator.guid(), {}, { status: 404 })
})
})
})

View file

@ -13,6 +13,7 @@ import { UserAPI } from "./user"
import { QueryAPI } from "./query"
import { RoleAPI } from "./role"
import { TemplateAPI } from "./template"
import { RowActionAPI } from "./rowAction"
export default class API {
table: TableAPI
@ -29,6 +30,7 @@ export default class API {
query: QueryAPI
roles: RoleAPI
templates: TemplateAPI
rowAction: RowActionAPI
constructor(config: TestConfiguration) {
this.table = new TableAPI(config)
@ -45,5 +47,6 @@ export default class API {
this.query = new QueryAPI(config)
this.roles = new RoleAPI(config)
this.templates = new TemplateAPI(config)
this.rowAction = new RowActionAPI(config)
}
}

View file

@ -0,0 +1,17 @@
import { CreateRowActionRequest, Row, RowAction } from "@budibase/types"
import { Expectations, TestAPI } from "./base"
export class RowActionAPI extends TestAPI {
save = async (
tableId: string,
rowAction: CreateRowActionRequest,
expectations?: Expectations,
config?: { publicUser?: boolean }
): Promise<Row> => {
return await this._post<RowAction>(`/api/tables/${tableId}/actions`, {
body: rowAction,
expectations,
...config,
})
}
}