- Instale as dependências do projeto:
yarn
||npm i
- Crie o banco de dados a seguir via docker:
docker run --name code_challenge_hox -e POSTGRES_PASSWORD=hox -p 5432:5432 -d postgres
- Crie o seguinte banco de dados de testes para conseguir realizar os testes de integração:
postgres_tests
- Rode as migrations para criação das tabelas no banco:
yarn typeorm migration:run
||npm run typeorm migration:run
- Para iniciar o servidor no modo de desenvolvimento:
yarn dev
||npm run dev
Baixe o arquivo Insomnia_2020-10-26.json
para realizar a importação ou importe diretamente via URL https://github.com/miguelsoliv/code-challenge-hox-nodejs/blob/master/Insomnia_2020-10-26.json
O projeto foi organizado com base no MVC e com princípios do SOLID adaptados
- Unitários (não é preciso ter o banco criado para rodar!):
yarn unit-test
||npm run unit-test
- Para facilitar a execução dos testes unitários foram criadas imitações dos repositórios de acesso ao Postgres (fake repositories). A cada execução dos testes o "banco" é zerado, pois os dados estão sendo salvos somente em memória
- Integração:
yarn integ-test
||npm run integ-test
- Todos:
yarn test
||npm run test
[POST] /users
Title | Get Scenario |
---|---|
URL | /users |
Method | POST |
URL Params | None |
Data Params | Required: name=[string] email=[string] password=[string] |
Success Response | Code: 201 CREATED Content: { "user": { "name": "User", "email": "user@example.com", "id": "77300ab1-26d4-4403-8905-c9ff67104bdc" }, "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" } |
Sample Request | { "name": "User", "email": "user@example.com", "password": "123456" } |
[POST] /session
Title | Get Scenario |
---|---|
URL | /session |
Method | POST |
URL Params | None |
Data Params | Required: email=[string] password=[string] |
Success Response | Code: 200 OK Content: { "user": { "name": "User", "email": "user@example.com", "id": "77300ab1-26d4-4403-8905-c9ff67104bdc" }, "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" } |
Sample Request | { "email": "user@example.com", "password": "123456" } |
[POST] /categories
Title | Get Scenario |
---|---|
URL | /categories |
Method | POST |
URL Params | None |
Data Params | Required: name=[string] |
Success Response | Code: 201 CREATED Content: { "category": { "name": "My Category", "id": "e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f" }} |
Sample Request | { "name": "My Category" } |
Notes | Authentication required |
[PUT] /categories/:id
Title | Get Scenario |
---|---|
URL | /categories/:id |
Method | PUT |
URL Params | Required: id=[string] |
Data Params | Required: name=[string] |
Success Response | Code: 200 OK Content: { "category": { "name": "My New Category", "id": "e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f" }} |
Sample Request | { "name": "My New Category" } |
Notes | Authentication required |
[DELETE] /categories/:id
Title | Get Scenario |
---|---|
URL | /categories/:id |
Method | DELETE |
URL Params | Required: id=[string] |
Data Params | Required: name=[string] |
Success Response | Code: 204 NO CONTENT |
Sample Request | /categories/e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f |
Notes | Authentication required |
[GET] /categories/:id
Title | Get Scenario |
---|---|
URL | /categories/:id |
Method | GET |
URL Params | Required: id=[string] |
Data Params | None |
Success Response | Code: 200 OK Content: { "category": { "name": "My New Category", "id": "e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f" }} |
Sample Request | /categories/e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f |
Notes | Authentication required |
[GET] /categories
Title | Get Scenario |
---|---|
URL | /categories |
Method | GET |
URL Params | None |
Data Params | None |
Success Response | Code: 200 OK Content: { "categories": [{ "name": "My New Category", "id": "e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f" }] } |
Sample Request | /categories |
Notes | Authentication required |
[POST] /products
Title | Get Scenario |
---|---|
URL | /products |
Method | POST |
URL Params | None |
Data Params | Required: name=[string] category_id=[string] expiration_date=[Date] manufacturing_date=[Date] perishable_product=[boolean] price=[number] |
Success Response | Code: 201 CREATED Content: { "product": { "name": "My Product", "id": "f6312dc0-ea4c-42ec-8c54-167dd43376cb", "category_id": "e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f", "manufacturing_date": "2020-10-24T06:09:36.466Z", "perishable_product": true, "expiration_date": "2020-10-24T06:09:36.466Z", "price": 123.59 }} |
Sample Request | { "name": "My Product", "category_id": "e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f", "expiration_date": "2020-10-24T06:09:36.466Z", "manufacturing_date": "2020-10-24T06:09:36.466Z", "perishable_product": true, "price": 123.59 } |
Notes | Authentication required |
[PUT] /products/:id
Title | Get Scenario |
---|---|
URL | /products/:id |
Method | PUT |
URL Params | Required: id=[string] |
Data Params | Required: name=[string] category_id=[string] expiration_date=[Date] manufacturing_date=[Date] perishable_product=[boolean] price=[number] |
Success Response | Code: 201 CREATED Content: { "product": { "name": "My New Product", "id": "f6312dc0-ea4c-42ec-8c54-167dd43376cb", "category_id": "e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f", "manufacturing_date": "2020-10-24T06:09:36.466Z", "perishable_product": false, "expiration_date": "2020-10-24T06:09:36.466Z", "price": 125 }} |
Sample Request | { "name": "My New Product", "category_id": "e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f", "expiration_date": "2020-10-24T06:09:36.466Z", "manufacturing_date": "2020-10-24T06:09:36.466Z", "perishable_product": false, "price": 125 } |
Notes | Authentication required |
[DELETE] /products/:id
Title | Get Scenario |
---|---|
URL | /products/:id |
Method | DELETE |
URL Params | Required: id=[string] |
Data Params | Required: name=[string] |
Success Response | Code: 204 NO CONTENT |
Sample Request | /products/f6312dc0-ea4c-42ec-8c54-167dd43376cb |
Notes | Authentication required |
[GET] /products/:id
Title | Get Scenario | |
---|---|---|
URL | /products/:id |
|
Method | GET |
|
URL Params | Required: id=[string] |
|
Data Params | None | |
Success Response | Success Response | Code: 201 CREATED Content: { "product": { "name": "My New Product", "id": "f6312dc0-ea4c-42ec-8c54-167dd43376cb", "category_id": "e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f", "manufacturing_date": "2020-10-24T06:09:36.466Z", "perishable_product": false, "expiration_date": "2020-10-24T06:09:36.466Z", "price": 125, "category": { "name": "My Category", "id": "e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f" } }} |
Sample Request | /products/f6312dc0-ea4c-42ec-8c54-167dd43376cb |
|
Notes | Authentication required |
[GET] /products/:page/:category/:orderBy?
Title | Get Scenario |
---|---|
URL | /products/:page/:category/:orderBy? |
Method | GET |
URL Params | Required: page=[number] category=[string] Optional: orderBy=[string] |
Data Params | None |
Success Response | Code: 200 OK Content: { "products": [{ "name": "My New Product", "id": "f6312dc0-ea4c-42ec-8c54-167dd43376cb", "category_id": "e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f", "manufacturing_date": "2020-10-24T06:09:36.466Z", "perishable_product": false, "expiration_date": "2020-10-24T06:09:36.466Z", "price": 125, "category": { "name": "My Category", "id": "e5d47ebe-1ad8-48b5-ae4f-7ffbe978fa7f" } }] } |
Sample Request | /products/1/My Category |
Notes | Authentication required |