-
Notifications
You must be signed in to change notification settings - Fork 1
Backend Tests
Dinith edited this page May 24, 2020
·
5 revisions
-
- Allows easy testing of any JS code
- Allows use of mocks
- Allows use of spies
-
- Allows mocking of Mongoose models
- Can mock Mongoose method calls on the models
-
- Allows mocking of a MongoDb server
- Creates an in-memory database
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
Metrinom has a single Mongoose 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
There are numerous API endpoints that Metrinom require to function correctly. All of these endpoints were test apart from two. These two endpoints are related to user Spotify account authorization. Testing was therefore done on all the /spotify
and /user
endpoints. To carry out the tests, the following was required:
- Checking the express server is configured and launched correctly with the required loaders and routes
- Launching an express server and making fetch calls to them
- Mocking of the
User
Mongoose model usingmockingoose
in order to create more efficient and targeted tests (ignore implementation of the Mongoose model) - Mocking of all methods tested in the 'Testing the vanilla JS code' section mentioned above
- Checking the status code and mock data return from each API call