import request from "supertest";


export class ApiHelpers {
    public static async getApiRequest(
        host: string,
        resource: string,
        contentType: string = "application/json",
        acceptHeader: string = "application/json",
    ): Promise<request.Response> {
        let response = await request(host)
            .get(resource)
            .set("Content-Type", contentType)
            .set("Accept", acceptHeader)
        return response;
    }

    public static async postApiRequest(
        host: string, resource: string,
        payLoad: object = {},
        contentType: string = "application/json",
        acceptHeader: string = "application/json"
    ): Promise<request.Response> {
        let response = await request(host)
            .post(resource)
            .set("Content-Type", contentType)
            .set("Accept", acceptHeader)
            .send(payLoad)
        return response;
    }

    public static async deleteApiRequest(
        host: string,
        resource: string,
        contentType: string = "application/json",
        acceptHeader: string = "application/json",
    ): Promise<request.Response> {
        let response = await request(host)
            .delete(resource)
            .set("Content-Type", contentType)
            .set("Accept", acceptHeader)
        return response;
    }

    public static async putApiRequest(
        host: string, resource: string,
        payLoad: object = {},
        contentType: string = "application/json",
        acceptHeader: string = "application/json"
    ): Promise<request.Response> {
        let response = await request(host)
            .put(resource)
            .set("Content-Type", contentType)
            .set("Accept", acceptHeader)
            .send(payLoad)
        return response;
    }
}
