Smithface / Sprint-Challenge--Testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Assessing your Testing Fu

  • 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.

Start by forking and cloning this repository.

Questions - Self Study - You can exercise your Google-Fu for this and any other Sprint Challenge in the future.

  1. In Mocha, what are the differences between before, after, beforeEach, and afterEach? When do they run? What are they used for?
  2. What is the point of Test Driven Development? What do you personally think about this approach?
  3. What is a spy in sinon? How do we use it to effectively test a callback?

Initializing Project -

  • 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 yarn to download and install all the dependencies you need for this project.
  • run yarn test to start your tests.
  • Keep an active log of your changes by commiting with Git and pushing often to GitHub.
  • Write all of your tests in the server.test.js file. This is where you're going to be doing your API mocking/testing.

Project Description

  • 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.

DOCUMENTATION:

Welcome to the NESgames API. To get started, the default port is 5050. Available endpoints are documented below.

Get the Full List of Games from the Database

[GET] /api/game/get

Parameters

N/A, a simple GET request is all that is needed.

Example Response

status: 200 OK

{
  "body": [
    {
      "id": "fo90ef8h209ufgh0e90f9",
      "title": "Excitebike",
      "genre": "Racing",
      "releaseDate": "November 30, 1984"
    },
    {
      "id": "gn40ef9h209uqgh0e30f1",
      "title": "Code Name: Vooper",
      "genre": "Action/Shooter",
      "releaseDate": "March 1990"
    }
  ]
}

Add a Game to the Database

[POST] /api/game/create

Request Body

Name Type Description
title string The title of the game you want to add to the database.
genre string The genre of the game.
releaseDate string The release date of the game.

Example Response (returns created game)

status: 200 OK

{
  "id": "fj248rh2049t8he09if209e8rh029",
  "title": "Pro Wrestling",
  "genre": "Fighting/Sports",
  "releaseDate": "March 1987"
}

Update a Game in the Database

[PUT] /api/game/update

Request Body

Name Type Description
id string The document whose title you want to update.
title string The new title for the game.

Example Response (returns the updated game)

status: 200 OK

{
  "body": {
      "id": "gn40ef9h209uqgh0e30f1",
      "title": "Code Name: Viper",
      "genre": "Action/Shooter",
      "releaseDate": "March 1990"
    }
}

Delete a Game from the Database

[DELETE] /api/game/destroy/:id

Parameters

Name Type Description
id string The document id, as generated by Mongoose.

Example Response (returns the deleted game)

status: 200 OK

{
  "body": [
    {
      "id": "fo90ef8h209ufgh0e90f9",
      "title": "Excitebike",
      "genre": "Racing",
      "releaseDate": "November 30, 1984"
    }
  ]
}

TESTS

  • 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 YARN START, BUT YOU'LL WANT TO ENSURE THAT YOU HAVE A MONGO INSTANCE UP AND RUNNING.

Write a test for the "POST" method

  • The POST method should take in an object that looks like this
{
  title: 'California Games',
  genre: 'Sports',
  date: 'June 1987'
}

Write a test for the "GET" method

  • 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 your DELETE

Write a test for the "PUT" method

  • 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

Stretch Problem

Write a test for the "DELETE" method

  • DELETE can take an ID off of the route parameter, or off of the req.body. It's your choice.

Remember you can use any resources you want to solve these problems, but avoid copying/pasting solutions you've previously written. Also if you don't finish all of the challenges, that's fine! Just do what you can and submit your challenges in the end! HAVE FUN!

About


Languages

Language:JavaScript 100.0%