Skip to content

Commit 848ba06

Browse files
author
Kristján Oddsson
authored
chore(test): mock all request responses (#376)
* chore(test): mock all request responses * chore(ci): run tests on circleci * fix(ci): put lint and test in seperate run lines * chore: make mock data json more human readable * feat: add a way to re-record mock data * fix(ci): disable weather test The upstream data source is currently broken so we're disablign the test for now. * chore(test): re-record the mock test data * Add a note about `nock` in the README docs
1 parent 9532eec commit 848ba06

File tree

6 files changed

+71672
-4
lines changed

6 files changed

+71672
-4
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
docker:
99
# specify the version you desire here
1010
- image: circleci/node:7.10
11-
11+
1212
# Specify service dependencies here if necessary
1313
# CircleCI maintains a library of pre-built images
1414
# documented at https://circleci.com/docs/2.0/circleci-images/
@@ -32,6 +32,6 @@ jobs:
3232
paths:
3333
- node_modules
3434
key: v1-dependencies-{{ checksum "package.json" }}
35-
36-
# run tests!
35+
3736
- run: yarn run lint
37+
- run: yarn run test

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ To run the tests:
3939
$ npm test
4040
```
4141

42+
The tests utilize a man-in-the-middle library called [nock](https://github.com/node-nock/nock) that
43+
intercepts requests that the tests made and respond with data from disk. The data was generated using
44+
the [record feature](https://github.com/node-nock/nock#recording) and saved in [`mock-data.json`](mock-data.json).
45+
46+
If a endpoints data source has changed and the we need to re-record this data we can simply set the
47+
env variable `RECORD_MOCK_DATA` to a truthy value and run the tests. This will disable nock in the tests
48+
and make requests to each endpoints data source and save that to disk.
49+
50+
```sh
51+
RECORD_MOCK_DATA=true npm test
52+
```
53+
54+
Newly added endpoints should mock the endpoints data source using the `nock` API since this initial
55+
data mocking was only made to help migrate to a mocking library. See the [original PR](https://github.com/apis-is/apis/pull/376)
56+
for more info.
57+
4258
## Adding a new Endpoint
4359

4460
### Step by Step

endpoints/weather/tests/integration_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('weather', () => {
1010
request.get(params, resultHandler)
1111
})
1212

13-
describe('getAvailableStations', () => {
13+
describe.skip('getAvailableStations', () => {
1414
it('should return an array of objects containing correct fields', (done) => {
1515
const fieldsToCheckFor = ['name', 'id']
1616
const params = helpers.testRequestParams('/weather/getAvailableStations')

0 commit comments

Comments
 (0)