All files / http-client client.ts

42.86% Statements 3/7
0% Branches 0/2
50% Functions 2/4
50% Lines 3/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                          58x     50x               50x    
import axios from "axios";
import { customIdentity, customPickBy } from "../utils";
import { lablebHttpClientSchema } from "./client.schema";
import { LablebHttpClientParams } from "./client.type";
 
function mapValues(obj: any, fn: any) {
 
    if (typeof obj == 'object')
        return Object.keys(obj).reduce((result, key) => ({
            ...result,
            [key]: fn(obj[key]),
        }), {});
 
    else
        return undefined;
 
}
 
 
export async function LablebHttpClient(options: LablebHttpClientParams) {
 
    const result = await lablebHttpClientSchema.validate(options);
 
 
    return axios(
        customPickBy({
            method: result?.method,
            url: result?.url,
            headers: result?.headers,
            data: result?.body,
            params: result?.params,
        }, customIdentity))
        .then((response: any) => response.data);
}