1
0
Fork 0
mirror of synced 2024-06-13 07:54:46 +12:00
budibase/qa-core/src/internal-api/api/apis/BaseAPI.ts

57 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-05-10 05:32:17 +12:00
import { Response } from "node-fetch"
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
export default class BaseAPI {
client: BudibaseInternalAPIClient
constructor(client: BudibaseInternalAPIClient) {
this.client = client
}
2023-07-15 11:12:18 +12:00
async get(url: string, status?: number): Promise<[Response, any]> {
2023-05-10 05:32:17 +12:00
const [response, json] = await this.client.get(url)
2023-07-15 11:12:18 +12:00
expect(response).toHaveStatusCode(status ? status : 200)
2023-05-10 05:32:17 +12:00
return [response, json]
}
async post(
url: string,
body?: any,
statusCode?: number
): Promise<[Response, any]> {
const [response, json] = await this.client.post(url, { body })
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
return [response, json]
}
async put(
url: string,
body?: any,
statusCode?: number
): Promise<[Response, any]> {
const [response, json] = await this.client.put(url, { body })
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
return [response, json]
}
async patch(
url: string,
body?: any,
statusCode?: number
): Promise<[Response, any]> {
const [response, json] = await this.client.patch(url, { body })
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
return [response, json]
}
2023-05-17 06:07:05 +12:00
async del(
url: string,
statusCode?: number,
body?: any
): Promise<[Response, any]> {
const [response, json] = await this.client.del(url, { body })
2023-05-10 05:32:17 +12:00
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
return [response, json]
}
}