This service serves an API of zombies and their items. All needed CRUD operations are available for both zombies
and their items
Returns an array containing all recorded zombies
Creates and returns a new zombie object
Retrieves a zombie object with total items value, by zombie's id
Updates a zombie by its id, accepts a JSON body representing the mutation object. It merges your mutation object with the object in the DB. Returns the updated object
Deletes a zombie by its id and returns {result: success}
Returns an array represting all zombie's items
Accepts a PUT request to replace the whole items array of in given zombie. Returns the updated zombie
Accepts a PATCH request to insert a single new item in given zombie's items. Returns the updated zombie
Returns a single zombie's item selected at the given index. Note that item's index should not be confused with item's id.
Deletes a zombie's item at the provided index
To run this app, you need to clone this repository and in its DIR do:
yarn
ornpm i
.yarn start
ornpm run start
.
The app will listen on port 3000 by default.
To run the tests, assuming you already did yarn
or npm i
, all you need to do is to run yarn test
or npm run test
.
- Integration tests: I tested against every supported endpoint disregarding implentation details.
- Unit tests: I tested every validation function in
apiActions/validators.js
.
I didn't test DBManager
class because it is tested fairly enough in the integeration tests, especially given the limited time for the project.
- I used
lowdb
as database for simplicity. - I used
node-fetch
for easy promisified HTTP requests. - I cached exchange rates for 1 hour.
- I cached zombie items for the whole 24h of their lifespan.
- I used
supertest
to test the API. - I used
mocha
for assertions and general testing. - I deployed on Zeit.
Please do not modify this file manually. It's automatically generated by running npm run build-docs
. To modify it, you can either edit tools/readme_source.md
or route descriptions under apiActions
directory.
Due to Zeit limitations; deployments filesystem is not persistent. Which makes the DB I am using volatile. All data disappears when the instance goes to light-sleep mode. I didn't work on a remote DB because it seems to be it isn't the scope of the task and can be a waste of time.
I created this curl
command to help you push a zombie with a few items without Postman's hassle or such.
curl 'http://localhost:3000/zombies' -H 'Content-Type: application/json;charset=UTF-8' --data-binary '{"name":"Omar","items":[{"id":3,"name":"Wooden Hoe"},{"id":1,"name":"Diamond Sword"}]}'
Please note that the /today
endpoint of NBP doesn't work on bank holidays as transfer rates are not updated. I had to use https://api.nbp.pl/api/exchangerates/tables/C/?format=json
endpoint instead. It returns the latest available exchange rates.
MIT