tiagodlb / Sing-Me-A-Song

Sing me a song it's a music finder, here you can share music or find a random one

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


'Sing me a song' Tests

WIP

Tests for the 'Sing me a song' project.
Browse TypeScript code»

Built With


Jest Coverage sing-me-a-song

Table of Contents

Installation and Usage

Pre-requisites: Node.js ^16.14.0, PostgreSQL ^12.11

There are two available options for you to use this template for your next Back End project: either use Github's built-in Use this api feature (green button left of the 'About' section), or download the zip file and extract it in the root of a new project folder by running these commands:

git clone https://github.com/tiagodlb/Sing-Me-A-Song.git

Then run the following command to install the project's dependencies:

npm install //OBS: you'll need to do this in both folders.

These are the back end commands that you'll need to know:

npm run build              // create the project build
npm run start              // run the project, not recommended since you'll need also have to change all the import directories
npm run dev                // recommended way to run the project
npm run prisma:reset       // reset the prisma database
npm run prisma:migrate     // migrate the prisma database, you should do this after the npm install
npm run prisma:prod        // starts prisma build production process, do this if you want to make a deploy 
npm run prisma:test        // resets the database in order to make the tests more accurate
npm run prisma:seed        // start the seeding process, create data in the database
npm run test               // resets the database in order to make the tests more accurate
npm run test:unit          // starts the testing process

These are the front end commands that you'll need to know:

npm run start         // starts the project
npm run cypress:open  // open cypress

Middlewares

While aiming to provide a reusable, modular and extensible architecture, the middlewares are generally the first structures to be refactored into self-contained modules. The errorHandlerMiddleware(), validateSchemaMiddleware() middlewares were set in order to achieve that goal. The following section describes useMiddleware(), which incorporates the forementioned functions as key–value pairs in an Object, along with their structure and usage.

API Reference

In this section, you will find the example API's endpoints and their respective descriptions, along with the request and response examples, as well as the Prisma models for each entity, that can be used as guide for data formatting. All data is sent and received as JSON.

Models

User model Recommendations

  • id: A unique identifier for each user. serial4
  • name: The recommendation title. text An title may only be registered once.
  • youtubeLink: The recommendations's youtube url. text

Routes

Items /recommendations

    POST /recommendations

  ☰   Request

Body
{
        "name": "Lorem ipsum",
        "youtubeLink": "www.youtube.com/seu-link",
}
Headers
{
  "Content-Type": "application/json"
}

  ☰   Responses

Status Code Description Properties
201 Created data: {}
409 Item already registered error: { type, message }
422 Invalid Input error: { type, message }
500 Internal Server Error error: { type, message }
    POST /recommendations/:id/downvote

  ☰   Request

Body
{
      //empty
}
Headers
{
  "Content-Type": "application/json"
}

  ☰   Responses

Status Code Description Properties
200 Created data: {}
404 Item already registered error: { type, message }
500 Internal Server Error error: { type, message }
    POST /recommendations/:id/upvote

  ☰   Request

Body
{
      //empty
}
Headers
{
  "Content-Type": "application/json"
}

  ☰   Responses

Status Code Description Properties
200 Created data: {}
404 Item already registered error: { type, message }
500 Internal Server Error error: { type, message }
    GET /recommendations/

  ☰   Request

Body
{
  //empty
}
Headers
{
  "Content-Type": "application/json"
}

  ☰   Responses

Status Code Description Properties
200 OK data: { recommendations }
500 Internal Server Error error: { type, message }
    GET /recommendations/:id

  ☰   Request

Body
{
  //empty
}
Headers
{
  "Content-Type": "application/json"
}

  ☰   Responses

Status Code Description Properties
200 OK data: { recommendation }
404 Item not found error: { type, message }
500 Internal Server Error error: { type, message }
    GET /recommendations/random

  ☰   Request

Body
{
  //empty
}
Headers
{
  "Content-Type": "application/json"
}

  ☰   Responses

Status Code Description Properties
200 OK data: { recommendation }
404 Item not found error: { type, message }
500 Internal Server Error error: { type, message }
    GET /recommendations/top/:amount

  ☰   Request

Body
{
  //empty
}
Headers
{
  "Content-Type": "application/json"
}

  ☰   Responses

Status Code Description Properties
200 OK data: { recommendations }
500 Internal Server Error error: { type, message }

Template created by Nivaldo Farias.

About

Sing me a song it's a music finder, here you can share music or find a random one


Languages

Language:HTML 62.6%Language:JavaScript 19.0%Language:TypeScript 14.8%Language:CSS 3.5%Language:Shell 0.0%