Testing

The backend has various end-to-end tests and unit tests ensuring that anything related to using data and mentorship requests is functional.

Important Information

Algolia powers the search functionality of the website. Algolia & MongoDB are kept in sync via an Object-Relation-Mapping library (typegoosearrow-up-right). However, typegoose does not seem to handle Algolia data cleanup correctly when deleting a temporary index.

triangle-exclamation

Setting up the testing credentials

Most of the time, you should be using the test credentials for the development too. A quick way to ensure you're using the right credentials is to make sure that Algolia's API keys are set to None

# Ensuring that the correct credentials are used:
$ cd packages/server
$ cat .env-test > .env 
$ cat .env
...
ALGOLIA_API_KEY=None
...

Infrastructure

tests
β”œβ”€β”€ data
β”‚Β Β  └── index.ts
β”œβ”€β”€ e2e
β”‚Β Β  β”œβ”€β”€ auth.ts
β”‚Β Β  β”œβ”€β”€ main.ts
β”‚Β Β  └── mentorship.ts
β”œβ”€β”€ unit
β”‚Β Β  β”œβ”€β”€ CommunicationService.ts
β”‚Β Β  β”œβ”€β”€ MentorshipService.ts
β”‚Β Β  └── UserService.ts
└── utils
    └── index.ts

4 directories, 8 files
  • data/

    • Contains mock data

  • e2e

    • Ensures API calls are valid and data validation works correctly.

  • unit

    • Smaller tests that focus on one functionality.

  • utils

    • Contains various tools for mocking external services. We do not want to mess with our production database or accrue API calls

Running tests

Our CI/CD pipeline run tests on every push & PR request made to the main branch. It's always good practice to run the tests before pushing:

Last updated