- Keep Calm! Test On!
- Now that you're familiar with the concepts of testing, your goal is to write documentation and tests for an API that is already in production. (This happens a lot :))
- Answers to your written questions will be recorded in Answers.md
- This is to be worked on alone but you can use outside resources. You can reference any old code you may have, and the React Documentation, however, please refrain from copying and pasting any of your answers. Try and understand the question and put your responses in your own words. Be as thorough as possible when explaining something.
- Just a friendly Reminder Don't fret or get anxious about this, this is a no-pressure assessment that is only going to help guide you here in the near future. This is NOT a pass/fail situation.
Questions - Self Study - You can exercise your Google-Fu for this and any other Sprint Challenge in the future.
- In Mocha, what are the differences between
before
after
beforeEach
afterEach
? When do they run? What are they used for? - What is the point of Test Driven Development? What do you personally think about this approach?
- What is a
spy
insinon
? How do we use it to effectively test acallback
?
- Fork/Clone this project into a directory on your machine.
cd
into your forked local copy.- notice there is a
package.json
file included. We have included all of the dev-dependencies that you'll need to build your project. - run
npm install
to download all the dependencies you need for this project. - run
npm test
to start your tests. - Keep an active log of your changes by
commiting
andpushing
often. - Write all of your tests in the
server.test.js
file. This is where you're going to be doing your API mocking/testing. - Once you're done writing all the tests, push your commits to your fork and submit a Pull-Request.
- You're going to be writing the documentation and the tests for a CRUD API.
- The API itself is really simple. You're task is to peek at the endpoints found in the
server.js
file and write docs for each one, then write the tests for the end points.
POST /api/game/create
Parameters:
Field | Type | Description |
---|---|---|
title |
string |
Required. Game title |
releaseDate |
string |
Year of game's release |
genre |
string |
Required. Game genre |
Example Input
{
title: 'Donkey Kong',
releaseDate: 'July 1981',
genre: 'Platformer'
}
Response Status
201 Created
GET /api/game/get
Response Status
200 OK
PUT /api/game/update
Parameters:
Field | Type | Description |
---|---|---|
title |
string |
Required. New game title |
ID |
string |
Required. Game ID being updated |
Response Status
201 Created
DELETE /api/game/destroy/:id
Parameters:
Note: A game can be deleted by placing it's id on the request body or in the request params.
Field | Type | Description |
---|---|---|
ID |
string |
Required. Game ID being deleted |
Response Status
200 OK
- I have already manually tested this API for you.
- All you have to do is write Unit tests to ensure that the end points do what they're supposed to do.
- THERE IS NO NEED TO NPM START. BUT YOU'LL WANT TO ENSURE THAT YOU HAVE A
MONGO
INSTANCE UP AND RUNNING.
- The Post method should take in an object that looks like this
{
title: 'California Games',
genre: 'Sports',
date: 'June 1987'
}
- Our get method should return the list of games.
- REMINDER That this data structure returned from Mongo will be an array, so to test your game with a
beforeEach
hook you'll need to make sure you test against the first item in the array
expect(res.data[0].foo).to.equal(bar.foo);
- Write your
PUT
and yourDELETE
- Just like in class, send up the information you want changed on the server via the
req.body
. - You can send up the Id and the Server will be using that to
- DELETE can take an ID off of the route parameter, or off of the req.body. It's your choice.