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

View File

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