1.0.0 • Published 7 years ago

fake-data-repository v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

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

fileresquest
/index.get.jsonGET /
/any.get.jsonGET /:id
/any.get.specific.jsonGET /:id {specific}
/_search.get.jsonGET /search
/_comments.get.jsonGET /comments
/comments/index.get.jsonGET /comments/
/comments/any.get.jsonGET /comments/:id
/comments/_search.get.jsonGET /comments/search
/comments/any/index.get.jsonGET /comments/:id/

example queries

fileresquest
/index?name=Superman.get.jsonGET /?name=Superman
/any?name=Batman.get.jsonGET /:id?name=Batman
/any?name=Batman.get.specific.jsonGET /:id?name=Batman {specific}

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