3.0.6 • Published 8 days ago

@natlibfi/fixugen-http-client v3.0.6

Weekly downloads
11
License
MIT
Repository
github
Last release
8 days ago

Generate unit tests for HTTP clients with fixugen

Generate unit tests with fixugen and mocks HTTP responses nock. Useful for modules that export a Javascript interface for i.e. REST APIs.

Uses fixugen's useMetadataFile so your fixture directories must contain metadata.json file.

Usage

import 'fetch' from 'node-fetch';
import {expect} from 'chai';
import generateTests from '@natlibfi/fixugen-http-client';

generateTests({
  callback,
  path: [__dirname, '..', 'test-fixtures']
});

function callback({getFixture}) {
  // The base URL is always http://foo.bar
  const response = await fetch('http://foo.bar');
  expect(response.status).to.equal(200);
}

Configuration

The following optional properties are supported in the factory function:

  • mocha: Mocha options
  • fixura: Fixura options
  • recurse: Fixugen's recurse option. Defaults to true

metadata.json

An array property requests must be present in metadata.json file. It supports the following properties:

  • status: HTTP status code (Number). Mandatory.
  • method: HTTP method in lowercase. Mandatory.
  • url: URL of the request. This is only the location and parameters part of the actual URL. The base URL is always http://foo.bar. Must start with /. Mandatory.
  • requestHeaders: An object representing requests headers.
  • responseHeaders: An object representing response headers.

This configuration is also passed to the callback as the property requests.

Request and response payloads

The fixture directory for each unit test can have request- and response payload fixtures which must match the following filename pattern: /^request[0-9]+ /^response[0-9]+

Where [0-9]+ denotes the index number of the fixture (Requests and responses are mocked in that order).

License and copyright

Copyright (c) 2020-2024 University Of Helsinki (The National Library Of Finland)

This project's source code is licensed under the terms of MIT or any later version.

3.0.6

8 days ago

3.0.6-alpha.1

8 days ago

3.0.5-alpha.2

12 days ago

3.0.5-alpha.1

12 days ago

3.0.5

12 days ago

3.0.4-alpha.1

4 months ago

3.0.4

4 months ago

3.0.3

5 months ago

3.0.3-alpha.1

5 months ago

3.0.2

6 months ago

3.0.1

7 months ago

3.0.0

10 months ago

3.0.0-alpha.1

10 months ago

3.0.1-alpha.2

7 months ago

3.0.2-alpha.1

6 months ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-alpha.2

4 years ago

1.0.0-alpha.1

4 years ago