Today, you will be adding automated testing to your Express API. You should have tests for each of the endpoints:
- GET
/gifs
which will list out all gifs - GET
/gifs/:id
which will get a gif with a specific ID - POST
/gifs
which will add a new gif and return that new gif - PUT
gifs/:id
which will update a gif and return that gif - DELETE
gifs/:id
which will delete a gif
Your code should make sure that each endpoint returns what it is supposed to. Directions for setting up testing and implementing tests can be found in the Express Testing lesson.
- First, fork and clone this repo and change directory into it.
- Run
npm i
to download required dependencies. - Make sure you have
mongodb
running! - Create a
.env
file and add yourDATABASE_URL
to it with your MongoDB Atlas connection string:
DATABASE_URL=mongodb+srv://dbuser:[email protected]/gaphyTestingLab?retryWrites=true&w=majority
- Run
node db/seed.js
to populate your database with seed data. - Run
nodemon index.js
to start your development server. You should see the following:
[nodemon] starting `node index.js`
Hello world! Express GAphy API listening on port 3000
mongo connected at: mongodb+srv://dbuser:[email protected]/gaphy?retryWrites=true&w=majority
✅ mongo connection made!
Happy coding!!!
If you have time, look up how to test a non-JSON webpage endpoint. Add testing to your MEHN lab using your research! You could also convert your application to an API and add testing to it that way if you prefer.