1
0
Fork 0
mirror of synced 2024-05-19 11:53:53 +12:00
budibase/qa-core/src/config/internal-api/TestConfiguration/tables.ts

53 lines
1.6 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 {
2022-10-25 21:02:55 +13:00
api: InternalAPIClient
constructor(apiClient: InternalAPIClient) {
this.api = apiClient
}
async getAll(expectedNumber: Number): Promise<[Response, Table[]]> {
const response = await this.api.get(`/tables`)
const json = await response.json()
expect(response).toHaveStatusCode(200)
expect(json.length).toBe(expectedNumber)
return [response, json]
}
async getTableById(id: string): Promise<[Response, Table]> {
const response = await this.api.get(`/tables/${id}`)
const json = await response.json()
2022-11-08 04:48:24 +13:00
expect(response).toHaveStatusCode(200)
expect(json._id).toEqual(id)
2022-10-25 21:02:55 +13:00
return [response, json]
}
2022-11-08 04:48:24 +13:00
async save(body: any, columnAdded?: boolean): Promise<[Response, Table]> {
2022-10-25 21:02:55 +13:00
const response = await this.api.post(`/tables`, { 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()
if (columnAdded) {
expect(json.schema.TestColumn).toBeDefined()
}
2022-10-25 21:02:55 +13:00
return [response, json]
}
async delete(
id: string,
revId: string
): Promise<[Response, responseMessage]> {
const response = await this.api.del(`/tables/${id}/${revId}`)
const json = await response.json()
2022-11-08 04:48:24 +13:00
expect(response).toHaveStatusCode(200)
expect(json.message).toEqual(`Table ${id} deleted.`)
2022-10-25 21:02:55 +13:00
return [response, json]
}
2022-10-19 22:42:57 +13:00
}