All files / http-client client.schema.ts

100% Statements 5/5
100% Branches 4/4
100% Functions 2/2
100% Lines 4/4

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        14x                   116x         37x 35x                
import * as yup from 'yup';
import { MESSAGES } from '../config/messages';
import { isValidHttpMethod } from '../utils';
 
export const lablebHttpClientSchema = yup.object().shape({
 
    method: yup
        .string()
        .required()
        .test('test-http-method', MESSAGES.WRONG_HTTP_METHOD, isValidHttpMethod),
 
    url: yup.string().required(),
 
    body: yup.mixed().when('method', {
        is: (value: string) => value == 'GET' || value == 'DELETE',
        then: yup.mixed()
            .test('test-not-required',
                MESSAGES.BODY_IS_NOT_ALLOWED_FOR_GET_OR_DELETE,
                (value: any) => {
                    if (value) return false;
                    return true;
                }),
        otherwise: yup.mixed().required(MESSAGES.BODY_IS_REQUIRED),
    }),
 
    params: yup.object().optional(),
    headers: yup.object().optional(),
});