1
0
Fork 0
mirror of synced 2024-06-02 18:44:54 +12:00
budibase/qa-core/src/config/internal-api/TestConfiguration/tables.ts

41 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-10-18 06:20:40 +13:00
import { Response } from "node-fetch"
2022-10-19 22:35:00 +13:00
import { Table } from "@budibase/types"
2022-10-18 06:20:40 +13:00
import InternalAPIClient from "./InternalAPIClient"
2022-10-19 05:29:13 +13:00
import { responseMessage } from "../fixtures/types/responseMessage"
2022-10-18 06:20:40 +13:00
export default class TablesApi {
api: InternalAPIClient
constructor(apiClient: InternalAPIClient) {
this.api = apiClient
}
2022-10-19 22:35:00 +13:00
async getAll(expectedNumber: Number): Promise<[Response, Table[]]> {
2022-10-18 06:20:40 +13:00
const response = await this.api.get(`/tables`)
const json = await response.json()
2022-10-19 05:29:13 +13:00
expect(response).toHaveStatusCode(200)
expect(json.length).toBe(expectedNumber)
2022-10-18 06:20:40 +13:00
return [response, json]
}
2022-10-19 05:29:13 +13:00
async getTableById(id: string): Promise<[Response, Table]> {
const response = await this.api.get(`/tables/${id}`)
2022-10-18 06:20:40 +13:00
const json = await response.json()
return [response, json]
}
2022-10-19 22:35:00 +13:00
async save(body: any): Promise<[Response, Table]> {
2022-10-18 06:20:40 +13:00
const response = await this.api.post(`/tables`, { body })
const json = await response.json()
return [response, json]
}
2022-10-19 22:35:00 +13:00
async delete(id: string, revId: string): Promise<[Response, responseMessage]> {
2022-10-19 05:29:13 +13:00
const response = await this.api.del(`/tables/${id}/${revId}`)
2022-10-18 06:20:40 +13:00
const json = await response.json()
return [response, json]
}
2022-10-19 22:42:57 +13:00
}