1
0
Fork 0
mirror of synced 2024-06-26 18:10:51 +12:00
budibase/qa-core/src/config/internal-api/TestConfiguration/rows.ts

40 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-10-19 22:35:00 +13:00
import { Response } from "node-fetch"
import { Row } from "@budibase/types"
import InternalAPIClient from "./InternalAPIClient"
export default class RowsApi {
2022-10-25 21:02:55 +13:00
api: InternalAPIClient
2022-11-08 04:48:24 +13:00
rowAdded: boolean
2022-10-25 21:02:55 +13:00
constructor(apiClient: InternalAPIClient) {
this.api = apiClient
2022-11-08 04:48:24 +13:00
this.rowAdded = false
2022-10-25 21:02:55 +13:00
}
2022-10-19 22:35:00 +13:00
2022-10-25 21:02:55 +13:00
async getAll(tableId: string): Promise<[Response, Row[]]> {
const response = await this.api.get(`/${tableId}/rows`)
const json = await response.json()
2022-11-08 04:48:24 +13:00
if (this.rowAdded) {
expect(response).toHaveStatusCode(200)
expect(json.length).toEqual(1)
}
2022-10-25 21:02:55 +13:00
return [response, json]
}
async add(tableId: string, body: any): Promise<[Response, Row]> {
const response = await this.api.post(`/${tableId}/rows`, { body })
const json = await response.json()
2022-11-08 04:48:24 +13:00
expect(response).toHaveStatusCode(200)
expect(json._id).toBeDefined()
expect(json._rev).toBeDefined()
expect(json.tableId).toEqual(tableId)
this.rowAdded = true
2022-10-25 21:02:55 +13:00
return [response, json]
}
2022-10-19 22:35:00 +13:00
2022-10-25 21:02:55 +13:00
async delete(tableId: string, body: any): Promise<[Response, Row[]]> {
const response = await this.api.del(`/${tableId}/rows/`, { body })
const json = await response.json()
2022-11-08 04:48:24 +13:00
expect(response).toHaveStatusCode(200)
2022-10-25 21:02:55 +13:00
return [response, json]
}
2022-10-19 22:42:57 +13:00
}