@cloudflare/test-www-api

1.0.28 • Public • Published

cf-test-www-api

Cloudflare WWW API Test Util

Installation

$ npm install cf-test-www-api

Usage

import assert from 'assert';
import {createApiResponse} from 'cf-test-www-api';

describe('exampleModule', () => {
  it('should do something', () => {
    const apiResponse = createApiResponse({
      id: 1,
      value: 'david-is-dumb'
    });

    assert.deepEqual(apiResponse, {
      success: true,
      result: {
        id: 1,
        value: 'david-is-dumb'
      },
      result_info: null,
      errors: null,
      messages: []
    });
  });

  it('should do something with lists', () => {
    const apiResponse = createApiResponse([{
      id: 1,
      value: 'david-is-dumb'
    }, {
      id: 2,
      value: 'and-really-annoying'
    }]);

    assert.deepEqual(apiResponse, {
      success: true,
      result: [{
        id: 1,
        value: 'david-is-dumb'
      }, {
        id: 2,
        value: 'and-really-annoying'
      }],
      result_info: {
        page: 1,
        per_page: 20,
        count: 2,
        total_count: 2
      },
      errors: null,
      messages: []
    });
  });

  it('should error', () => {
    const apiResponse = createApiResponse(null, [
      { code: 1, message: 'This is an error' }
    ]);

    assert.deepEqual(apiResponse, {
      success: false,
      result: null,
      result_info: null,
      errors: [
        { code: 1, message: 'This is an error' }
      ],
      messages: []
    });
  });

  it('should have messages', () => {
    const apiResponse = createApiResponse(null, null, [
      'This is a message'
    ]);

    assert.deepEqual(apiResponse, {
      success: true,
      result: null,
      result_info: null,
      errors: null,
      messages: ['This is a message']
    });
  });
});

Readme

Keywords

none

Package Sidebar

Install

npm i @cloudflare/test-www-api

Weekly Downloads

964

Version

1.0.28

License

BSD-3-Clause

Unpacked Size

9.11 kB

Total Files

7

Last publish

Collaborators

  • lerwincf
  • lbarthonet
  • cf-media-manager
  • jacobbednarz
  • celso
  • cf-radar
  • dash_service_account
  • g4brym
  • snigdha34
  • wrangler-publisher
  • marksteyn
  • chiminator
  • sgoodhew_cf
  • terinjokes
  • third774
  • jsteinberger
  • jasnell
  • asapzacy
  • pcostanzo
  • gregbrimble
  • geelen
  • rexscaria
  • dcruz_cf
  • xuranwang
  • jculvey
  • sejoker
  • vasturiano
  • cf-ci-write
  • segments-write
  • thibmeu
  • xortive
  • gurjinder
  • cf-ci2
  • lvalenta
  • worenga