Skip to content

Backend Tests

Dinith edited this page May 24, 2020 · 5 revisions

Testing tools used:

  • jest

    • Allows easy testing of any JS code
    • Allows use of mocks
    • Allows use of spies
  • mockingoose

    • Allows mocking of Mongoose models
    • Can mock Mongoose method calls on the models
  • mongodb-memory-server

    • Allows mocking of a MongoDb server
    • Creates an in-memory database

Testing the vanilla JS code

Testing of the backend's methods was done, namely the methods that make API calls to Spotify's API. This required the following:

  • Mocking of the node-fetch module, which was used to make API calls
  • Checking the number of calls to the fetch method
  • Checking the inputs to the fetch method

Testing the Mongoose Models + MongoDb

Metrinom has one model - User. This stores user information made to use API calls and display non-sensitive user data on the frontend. User JSON objects are stored in a collection of the MongoDb database. This required the following:

  • Use of monogodb-memory-server to mock a database
  • Checking retrieval, creation and deletion of User objects from/to the database

Testing the Express API