import { IHeader , IResponse , TestHttpService } from '@kentico/kontent-core' ; import { defaultPropertyNameResolver } from '.' ; import { createDeliveryClient , IDeliveryClient , IDeliveryClientConfig } from '../../../lib' ; const testProjectId = 'delivery-project-id' ; export function toPromise < T > ( data ) { return new Promise ( ( resolve , reject ) => { resolve ( data ) ; } ) ; } export function getTestDeliveryClient ( config ? ) { return createDeliveryClient ( config ? config : { propertyNameResolver : defaultPropertyNameResolver , projectId : testProjectId } ) ; } export function getDeliveryClientWithError ( errorJson ) { return createDeliveryClient ( { projectId : testProjectId , propertyNameResolver : defaultPropertyNameResolver , httpService : new TestHttpService ( { response : undefined , error : errorJson } ) } ) ; } export function getDeliveryClientWithJson ( json , config ? , responseHeaders = [ ] ) { return getDeliveryClientWithJsonAndHeaders ( json , config , responseHeaders ) ; } export function getDeliveryClientWithJsonAndHeaders ( json , config ? , responseHeaders = [ ] ) { if ( ! config ) { return createDeliveryClient ( { projectId : testProjectId , propertyNameResolver : defaultPropertyNameResolver , httpService : new TestHttpService ( { response : getResponseFromJson ( json , responseHeaders ) , error : undefined } ) } ) ; } config . httpService = new TestHttpService ( { response : getResponseFromJson ( json , responseHeaders ) , error : undefined } ) ; return createDeliveryClient ( config ) ; } function getResponseFromJson ( json , responseHeaders = [ ] ) { return { data : json , headers : responseHeaders , rawResponse : json , status : 999 , retryStrategy : { retryAttempts : 1 , options : { } } } ; }