fake-data-repository

1.0.0 • Public • Published

fake-data-repository

Provides access to fake data file system repository to help with testing.

Using FakeData Repository

The FakeData Repository class is a useful class for locating a fake response file based on the endpoint you provide.

Example:

const fakeDataRepo = new FakeDataRepository('test/fakedata/data/api')
const fakeDataResponse = fakeDataRepo.responses().get('/v1/Toronto')

The FakeDataRepository constructor takes a base path where it expects to find fake data.

To get fake response data from a GET request the method responses() is first called to tell the object to look in the responses folder, then the method get() is called taking a path as an argument to find the fakedata file. Other supported methods are put(), post(), and delete().

Look at unit tests for more example usages.

examples

file resquest
/index.get.json GET /
/any.get.json GET /:id
/any.get.specific.json GET /:id {specific}
/_search.get.json GET /search
/_comments.get.json GET /comments
/comments/index.get.json GET /comments/
/comments/any.get.json GET /comments/:id
/comments/_search.get.json GET /comments/search
/comments/any/index.get.json GET /comments/:id/

example queries

file resquest
/index?name=Superman.get.json GET /?name=Superman
/any?name=Batman.get.json GET /:id?name=Batman
/any?name=Batman.get.specific.json GET /:id?name=Batman {specific}

*Queries must be an exact match /any?name=Batman&villain=Joker.get.json will NOT match GET /:id?name=Batman

Readme

Keywords

none

Package Sidebar

Install

npm i fake-data-repository

Weekly Downloads

1

Version

1.0.0

License

ISC

Last publish

Collaborators

  • arbraini