Add base api class
This commit is contained in:
parent
7facf0c9ea
commit
62238611bf
|
@ -0,0 +1,52 @@
|
|||
import { Response } from "node-fetch"
|
||||
import BudibaseInternalAPIClient from "../BudibaseInternalAPIClient"
|
||||
|
||||
export default class BaseAPI {
|
||||
client: BudibaseInternalAPIClient
|
||||
|
||||
constructor(client: BudibaseInternalAPIClient) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
async get(url: string): Promise<[Response, any]> {
|
||||
const [response, json] = await this.client.get(url)
|
||||
expect(response).toHaveStatusCode(200)
|
||||
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]
|
||||
}
|
||||
|
||||
async del(url: string, statusCode?: number): Promise<[Response, any]> {
|
||||
const [response, json] = await this.client.del(url)
|
||||
expect(response).toHaveStatusCode(statusCode ? statusCode : 200)
|
||||
return [response, json]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue