Skip to content

GabrielaTiago/Sing-me-a-Song-TESTS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

microphone emoji

Sing me a Song

Unit, Integration, E2E

TypeScript Cypress Jest Express Node React Prisma PostgreSQL docker docker-compose swagger ESLint Prettier

πŸ“‹ Description

This project was meant to be a place where users can recommend and view music recommendations. The more recommendations a song receives, the better ranked it will be, increasing its possibility of being recommended to other users.

In this way, a test system was created to ensure the functioning of the API provided, as well as the frontend application. Checking in a unitary way the services functions, all route integration and the user experience on the website running.

βœ… Tests

  • Creation of a new recommendation
  • Upvote e downvote any recommendation
  • Get the latest recommendations
  • Get a recommendation
  • Get a random recommendation
  • Get top recommendations
  • Delete a recommendation with score less than -5

πŸ“š API Documentation

The API documentation, implemented with Swagger, can be accessed at the route /documentation

routes

πŸš€ Running this Project

First of all, clone this project and access the folder

    git clone https://github.com/GabrielaTiago/Sing-me-a-Song-TESTS.git
    cd Sing-me-a-Song-TESTS

⚠️ There are two ways to run this project:

  • Locally: you need to have Node.js, npm and Postgres installed on your machine.

  • With Docker: you need to have Docker and Docker Compose installed on your machine. With this option, you don't need to install these dependencies on your machine, since the project will run in containers.

βš™οΈ Environment Variables

The project uses the following environment variables:

Backend

  • PORT: Port where the server will run
  • POSTGRES_USER: Postgres username
  • POSTGRES_PASSWORD: Postgres user password
  • DATABASE_URL: Postgres database connection string

Copy the following content to create the .env and the .env.test files in the root of the backend project

    cd BACKEND
    cp .env.example .env
    cp .env.example .env.test
    cd ..

Then, replace the values in the files with your own configuration.

    # .env
    PORT=4000
    POSTGRES_USER=[YourUserName]
    POSTGRES_PASSWORD=[YourPassword]
    DATABASE_URL="postgres://[YourUserName]:[YourPassword]@localhost:5432/singmeasong";
    # .env.test
    PORT=4000
    POSTGRES_USER=[YourUserName]
    POSTGRES_PASSWORD=[YourPassword]
    DATABASE_URL="postgres://[YourUserName]:[YourPassword]@localhost:5432/singmeasong-test";

Frontend

  • REACT_APP_BASE_URL: Base URL for the frontend
  • REACT_APP_API_BASE_URL: Base URL for the API

Copy the following content to create the .env file in the root of the frontend project

    cd FRONTEND
    cp .env.example .env
    cd ..

🐳 Running Tests with Docker

Make sure you have Docker and Docker Compose installed on your machine.

You must update the DATABASE_URL in the .env.test located in the BACKEND folder.

    DATABASE_URL=postgres://[YourUserName]:[YourPassword]@sing-me-a-song-db-test:5432/singmeasong-test

Then, run the following command in the root of the project:

    npm run test:e2e

This command will build the Docker images and start the containers for the backend, frontend, and database. The backend will be available at http://localhost:4000 and the frontend at http://localhost:3000.

To run the cypress tests, open a new terminal and run the following command:

   cd FRONTEND && npx cypress open

Then, follow the steps in the Running the cypress tests section.

To run the backend unit and integration tests, open a new terminal and run the following command:

   cd BACKEND
    npm run docker:test

To stop and remove the containers, run the following command in the root of the project:

    npm run docker:down

πŸ’» Running Tests Locally

Enter the BACKEND folder

    cd BACKEND

Run the following command to install the dependencies.

    npm install

Generate the database with the following command

    npm run db

Then build the project

    npm run build

To start the server, run the command

    npm run start

To run the backend unit and integration tests, run the command

    npm run test

To run unit tests only, run the command

    npm run test:unit

To run integration tests only, run the command

    npm run test:integration

Now, open a new terminal and enter the FRONTEND folder

    cd FRONTEND

Run the following command to install the dependencies.

    npm install

Then build the project

    npm run build

To start the server, run the command

    npm run start

Start the cypress

    npx cypress open

Then, follow the steps in the Running the cypress tests section.

πŸ§ͺ Running the cypress tests

After opening cypress:

  • Click on E2E Testing in cypress environment;
  • Click on the option Electron

cypress gif

πŸ›‘ Attention: For the tests with cypress E2E to work properly, you should keep the server on the backend and frontend running.

commands screenshot

πŸ’‘ Acknowledgements

πŸ‘©πŸ½β€πŸ’» Author

Gabriela Tiago de AraΓΊjo


πŸ” Back to top

About

21th project from Driven Web Dev Fullstack Bootcamp

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •