Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Generate unit tests with fixugen and mocks HTTP responses [nock](https://www.npm

Uses [fixugen's](https://www.npmjs.com/package/@natlibfi/fixugen) **useMetadataFile** so your fixture directories must contain **metadata.json** file.

*NOTE*: from version 4.0.0 onwards fixugen-http-client-js uses undici insteads of nock and won't work for testing stuff that uses node-fetch instead of node native fetch

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

Expand All @@ -30,8 +31,9 @@ The following optional properties are supported in the factory function:
## 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**.
- **method**: HTTP method in uppercase. **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**.
- **query**: An object representing requests query parameters (Note: these can also be given as string as part of **url**)
- **requestHeaders**: An object representing requests headers.
- **responseHeaders**: An object representing response headers.

Expand All @@ -42,7 +44,8 @@ The fixture directory for each unit test can have request- and response payload
`/^request[0-9]+`
`/^response[0-9]+`

Where `[0-9]+` denotes the index number of the fixture (Requests and responses are mocked in that order).
Where `[0-9]+` denotes the order in which requests and responses are mocked (at least for single digits). Note that if unit test has several requests, request and response payload fixtures are matched to these in order, regardless of the digit used in file name. (Ie if we have three requests and request1.txt and response3.txt fixtures, both request1.txt and response3.txt get mapped to first request and rest of the request do not have request or response payload fixtures available.)


## License and copyright

Expand Down
Loading