Test project with NestJS, MongoDB, and RabbitMQ. Contains thorough end-to-end, integration, and unit tests on Jest test suite.
Service requires MongoDB and RabbitMQ to operate. You have to either provide these services, or use the command below to build a containerized version of them in your local machine:
docker compose up
Then provide the following environment variables for the service. You can store them in a .env
-style file.
Variable | Description | Default |
---|---|---|
APP_PORT | The port application listens to. | 3000 |
MAIL_SMTP_SERVER_DOMAIN | SMTP server domain name to connect. | gmail.com |
MAIL_SMTP_SERVER_PORT | SMTP server port to connect. | 25 |
MAIL_SERVICE_ADDRESS | Service's email address. | [email protected] |
MAIL_ADMIN_ADDRESS | Service admin's email address. | [email protected] |
MONGO_ROOT_USERNAME | MongoDB root username. | root |
MONGO_ROOT_PASSWORD | MongoDB root password. | |
MONGO_HOST | MongoDB host. | localhost |
MONGO_PORT | MongoDB port. | 27017 |
MONGO_DATABASE | Service's database name. | payever |
RMQ_HOST | RabbitMQ host. | localhost |
RMQ_PORT | RabbitMQ port. | 5672 |
FILE_SYSTEM_AVATAR_STORAGE_PATH | Directory name in file systemto store fetched avatars. | avatar |
REQRES_BASE_URL | Base URL for reqres website | https://reqres.in |
MOCKSERVER_PORT | Mockserver port (only used in integration tests). | 10001 |
To install required packages:
npm install
To start the service:
npm run start
Code includes three test packages
Provide test/e2e/.env.e2e
file with environment variables that the service is going to use in end-to-end tests. Then run the following:
npm run test:e2e
Provide test/e2e/.env.integration
file with environment variables that the service is going to use in integration tests. Note that in integration tests, not all of modules and APIs are going to be used simultaneously, so each integration test suite only uses the environment variables that are relevent to it. Run the following command to run integration tests:
npm run test:inte
To run unit tests, use the command below:
npm run test:unit