Have ideas to improve npm?Join in the discussion! »

    This package has been deprecated

    Author message:

    Functionality moved to @kentico/kontent-core

    @kentico/kontent-test-http-service-js
    TypeScript icon, indicating that this package has built-in type declarations

    2.1.0 • Public • Published

    Kentico Kontent Test HTTP Service for Kontent JavaScript SDKs

    npm npm npm Stack Overflow

    Build Status dependency Status

    Maintainability Test Coverage

    This is the source for the npm package called @kentico/kontent-test-http-service-js.

    This package is meant to be used as a fake HTTP Service when testing the Kentico Kontent Delivery SDK and Kentico Kontent Management SDK. It is basically an implementation of IHttpService that could be used when configuring the Delivery client or configuring Management client.

    Install

    With npm:

    npm install @kentico/kontent-test-http-service-js

    Usage

    This it the example of the usage. The object fakeResponseConfig could contain multiple entries. An entry is chosen by matching the request url against the regular expression pattern provided as a key.

    The full example is in delivery client tests.

    const fakeResponseConfig = new Map<RegExp, FakeResponseConfig>()
    fakeResponseConfig.set(
      // THIS IS A PATTERN THAT WOULD BE USED FOR MATCHING WHEN
      // QUERYING THE DATA AGAINST THE URL
      /https:\/\/deliver.kontent.ai\/.*\/items/,  
      {
        // HERE YOU PROVIDE YOUR FAKE RESPONSE FOR THIS PATTERN
        fakeResponseJson: {
          items: [
            {
              system: {...},
              elements: {...}
            }
          ],
          modular_content: {
            ...
          }
          pagination{
            continuation_token: null,
            next_page: null
          }
        },
        throwError: false,
        fakeHeaders: [{
           header: 'dummy-header-name',
           value: 'dummy value'
           }],
        fakeStatus: 200
      });
     
    const fakeHttpService =
     new KontentTestHttpService(fakeResponseConfig);
     
    const deliveryClientConfig = {
          projectId: 'dummyProject',
          typeResolvers: [],
          httpService: fakeHttpService
        };
     
    const client = new DeliveryClient(deliveryClientConfig)

    Author

    Ondřej Chrastina — @Simply007

    Thanks

    Analytics

    Keywords

    none

    Install

    npm i @kentico/kontent-test-http-service-js

    DownloadsWeekly Downloads

    64

    Version

    2.1.0

    License

    MIT

    Unpacked Size

    13.1 kB

    Total Files

    9

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar