Use test api for patch

This commit is contained in:
Adria Navarro 2023-07-26 12:29:19 +02:00
parent 9bb1cfcc7a
commit 77c2ce590c
3 changed files with 37 additions and 17 deletions

View File

@ -399,17 +399,12 @@ describe("/rows", () => {
const rowUsage = await getRowUsage()
const queryUsage = await getQueryUsage()
const res = await request
.patch(`/api/${table._id}/rows`)
.send({
const res = await config.api.row.patch(table._id!, {
_id: existing._id,
_rev: existing._rev,
tableId: table._id,
name: "Updated Name",
})
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
expect((res as any).res.statusMessage).toEqual(
`${table.name} updated successfully.`
@ -430,16 +425,16 @@ describe("/rows", () => {
const rowUsage = await getRowUsage()
const queryUsage = await getQueryUsage()
await request
.patch(`/api/${table._id}/rows`)
.send({
await config.api.row.patch(
table._id!,
{
_id: existing._id,
_rev: existing._rev,
tableId: table._id,
name: 1,
})
.set(config.defaultHeaders())
.expect(400)
},
{ expectStatus: 400 }
)
await assertRowUsage(rowUsage)
await assertQueryUsage(queryUsage)

View File

@ -1,13 +1,16 @@
import TestConfiguration from "../TestConfiguration"
import { RowAPI } from "./row"
import { TableAPI } from "./table"
import { ViewV2API } from "./viewV2"
export default class API {
table: TableAPI
viewV2: ViewV2API
row: RowAPI
constructor(config: TestConfiguration) {
this.table = new TableAPI(config)
this.viewV2 = new ViewV2API(config)
this.row = new RowAPI(config)
}
}

View File

@ -0,0 +1,22 @@
import { PatchRowRequest } from "@budibase/types"
import TestConfiguration from "../TestConfiguration"
import { TestAPI } from "./base"
export class RowAPI extends TestAPI {
constructor(config: TestConfiguration) {
super(config)
}
patch = async (
tableId: string,
row: PatchRowRequest,
{ expectStatus } = { expectStatus: 200 }
) => {
return this.request
.patch(`/api/${tableId}/rows`)
.send(row)
.set(this.config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(expectStatus)
}
}