This project uses Jest and Supertest for end-to-end testing of the API. The tests simulate real user interactions with the API and check that it behaves as expected.
To run the end-to-end tests, use the following command:
npm run test:e2e
This will start Jest and run all test files in the e2e directory. Each test file corresponds to a different part of the API.
End-to-end tests are a great way to ensure that your API works as expected and that it continues to work as you make changes to it. They can help you catch bugs early and avoid regressions in your code.
This kind of testing is essential for any production application, as it helps you try out the services and database connections in a real-world scenario.
Tech Stack | Badge |
---|---|
Node.js | |
Express.js | |
Docker | |
PostgreSQL | |
Jest | |
Supertest |
To install the project, run the following command:
npm install
After that is necessary to create the .env file with the following content:
PORT = 3000
DATABASE_URL= postgres://<use>:<pass>@localhost:5432/my_store
API_KEY= 12345
JWT_SECRET='secret123456'
SMTP_EMAIL=your@email.com
SMTP_PASSWORD=password-email
In this case we are using docker to create the postgres database, so you need to have docker installed on your machine.
Then you can connect to the database and create the database with the following command:
docker-compose exec postgres bash
psql -h localhost -d my_store -U <user>
\d+
SELECT * FROM users;
DELETE FROM users WHERE id=<id>;
npm run migrations:run
npm run test:coverage
Which is the npm task that runs the jest with the --coverage flag. This will generate a coverage folder with the index.html file that you can open in your browser to see the coverage report. The entire task is configured in the package.json file.
The folder name was configured in the jest-e2e.json file, so its name is coverage-e2e.
This project is licensed under the MIT License - see the LICENSE file for details.