Skip to content

chore(test): mock all request responses #376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 13, 2017
Merged
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
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
docker:
# specify the version you desire here
- image: circleci/node:7.10

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
Expand All @@ -32,6 +32,6 @@ jobs:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

# run tests!

- run: yarn run lint
- run: yarn run test
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ To run the tests:
$ npm test
```

The tests utilize a man-in-the-middle library called [nock](https://github.com/node-nock/nock) that
intercepts requests that the tests made and respond with data from disk. The data was generated using
the [record feature](https://github.com/node-nock/nock#recording) and saved in [`mock-data.json`](mock-data.json).

If a endpoints data source has changed and the we need to re-record this data we can simply set the
env variable `RECORD_MOCK_DATA` to a truthy value and run the tests. This will disable nock in the tests
and make requests to each endpoints data source and save that to disk.

```sh
RECORD_MOCK_DATA=true npm test
```

Newly added endpoints should mock the endpoints data source using the `nock` API since this initial
data mocking was only made to help migrate to a mocking library. See the [original PR](https://github.com/apis-is/apis/pull/376)
for more info.

## Adding a new Endpoint

### Step by Step
Expand Down
2 changes: 1 addition & 1 deletion endpoints/weather/tests/integration_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('weather', () => {
request.get(params, resultHandler)
})

describe('getAvailableStations', () => {
describe.skip('getAvailableStations', () => {
it('should return an array of objects containing correct fields', (done) => {
const fieldsToCheckFor = ['name', 'id']
const params = helpers.testRequestParams('/weather/getAvailableStations')
Expand Down
Loading