Kentico Cloud JS SDK Test Http Service
![Stack Overflow](https://img.shields.io/badge/Stack%20Overflow-ASK%20NOW-FE7A16.svg?logo=stackoverflow&logoColor=white)
![dependency Status](https://img.shields.io/david/Kentico/kentico-cloud-js-sdk-test-http-service.svg?maxAge=1000)
![Maintainability](https://api.codeclimate.com/v1/badges/f22cad469cc8779c2583/maintainability)
This is source for npm package called kentico-cloud-js-sdk-test-http-service
.
This package is meant to be used as a fake Http Service when testing Kentico Cloud Delivery SDK. It is basically an implementation of IHttpService that could be used when configuring Delivery client.
Install
With npm
:
npm install kentico-cloud-js-sdk-test-http-service
Or with yarn
yarn add kentico-cloud-js-sdk-test-http-service
Usage
This it the example of the usage. Object fakeResponseConfig
could contain multiple entries - entry is chosen by matching request url against the regular expression pattern provided as a key.
Full example is in delivery client tests.
const fakeResponseConfig = new Map<RegExp, FakeResponseConfig>()
fakeResponseConfig.set(
/https:\/\/deliver.kenticocloud.com\/.*\/items/,
{
fakeResponseJson: {
items: [
{
system: {...},
elements: {...}
}
],
pagination: {
continuation_token: null,
next_page: null
}
},
throwCloudError: false
});
const fakeHttpService =
new KenticoCloudJsSdkTestHttpService(fakeResponseConfig);
const deliveryClientConfig = {
projectId: 'dummyProject',
typeResolvers: [],
httpService: fakeHttpService
};
const client = new DeliveryClient(deliveryClientConfig)
Author
Ondřej Chrastina — @Simply007
Thanks
![Analytics](https://kentico-ga-beacon.azurewebsites.net/api/UA-69014260-4/Kentico/kentico-cloud-js-sdk-test-http-service?pixel)