Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c740826
chore: add npm
ETomacheski Mar 13, 2021
bfe7e11
chore: add git-commit-msg-linter
ETomacheski Mar 13, 2021
a9c97ca
chore: add typescript
ETomacheski Mar 13, 2021
34a9b8a
chore: add eslint
ETomacheski Mar 13, 2021
ec8ec65
chore: add jest
ETomacheski Mar 13, 2021
700b8f4
chore: add ts-node
ETomacheski Mar 13, 2021
8389d71
chore: add ts-jest
ETomacheski Mar 13, 2021
f267535
feat: ensure SingUpService return 400 if name is not provided
ETomacheski Mar 13, 2021
d41e6a2
test: ensure SingUpService return 400 if name is not provided
ETomacheski Mar 13, 2021
3017e98
refactor: move interfaces to file
ETomacheski Mar 13, 2021
a5f8eb6
feat: ensure SignUp return 200 is valid data provided
ETomacheski Mar 13, 2021
44dc9ad
test: ensure SignUp return 200 is valid data provided
ETomacheski Mar 13, 2021
ebca440
chore: add sequelize
ETomacheski Mar 13, 2021
f6f37e5
feat: ensure Singup controller register user in database
ETomacheski Mar 14, 2021
c4a5bf4
test: ensure Singup controller register user in database
ETomacheski Mar 14, 2021
57f3431
feat: ensure Singup return 500 if sequelize returns throws
ETomacheski Mar 14, 2021
1f7b094
test: ensure Singup return 500 if sequelize returns throws
ETomacheski Mar 14, 2021
b86825b
feat: ensure UpdatedUser updated user if valid dados is providad
ETomacheski Mar 14, 2021
4043e38
test: ensure UpdatedUser updated user if valid dados is providad
ETomacheski Mar 14, 2021
24f47dd
refactor: simplify code
ETomacheski Mar 14, 2021
ca4fb5e
feat: ensure DeleteUser deleted user if id is provided
ETomacheski Mar 14, 2021
33c16c4
test: ensure DeleteUser deleted user if id is provided
ETomacheski Mar 14, 2021
cf51c6e
test: ensure GetUser return user if id is provided
ETomacheski Mar 14, 2021
8ea1642
test: ensure GetUser return user if id is provided
ETomacheski Mar 14, 2021
c1d8b63
chore: add and config express
ETomacheski Mar 15, 2021
70b36d4
feat: add endPoints access
ETomacheski Mar 15, 2021
53ebecd
feat: att readme
ETomacheski Mar 15, 2021
6ed8061
feat: att readme
ETomacheski Mar 15, 2021
1a9035c
feat: att readme
ETomacheski Mar 15, 2021
f186a8e
chore: add scripts
ETomacheski Mar 15, 2021
64ada5a
Update README.md
ETomacheski Mar 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
dev.env
test.env
5 changes: 5 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const path = require('path');
module.exports = {
config: path.resolve(__dirname,'src','config','database.js'),
'migrations-path':path.resolve(__dirname,'src','database','migrations'),
};
149 changes: 103 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,124 @@
# Raks Back-end Developer Test

Be sure to read **all** of this document carefully, and follow the guidelines within.
<h1 align="center">

Teste realizado para a vaga de backend Jr Racks

</h1>
## Link da API: https://node-test-raks.herokuapp.com/

## **:computer: API NodeJS endpoints**

- **/user/:id** Get User
- **/user/** Post Criar usuários
- dados
```json
{
"name": "",
"address": "" ,
"dob": "",
"description": ""
}
```
- **/user/:id** Put atualizar dados do usuário
- dados
```json
{
"name": "",
"address": "" ,
"dob": "",
"description": ""
}
```
- **/user/:id** Delete deletar usuário

## Arquivo .env
Precisa adicionar dois .env, um dev.env que é para o arquivo de produção e um test.env
para fazer os test


```json

DB_HOST = ''
DB_USER = ''
DB_PASS = ''
DB_PASS = ''

```
### **Executando o Projeto**

## Context
#### **:computer: Backend**
> 1. $npm install
> 2. $npm start
> 3. No seu navegador, acesse localhost:3333
> 4. Enjoy!

Build a RESTful API that can `create/read/update/delete` user data from a persistence store.

### User Model
<!-- Website Links -->

```
{
"id": "xxx", // user ID (must be unique)
"name": "backend test", // user name
"dob": "", // date of birth
"address": "", // user address
"description": "", // user description
"createdAt": "" // user created date
"updatedAt": "" // user updated date
}
```
[shawee_site]: https://shawee.io/pt/

<!-- Badges -->

[github_issues_badge]: https://img.shields.io/github/issues/x0n4d0/ecoleta?color=green

[repository_license_badge]: https://img.shields.io/github/license/x0n4d0/ecoleta

[node_version_badge]: https://img.shields.io/badge/node-12.17.0-green

[npm_version_badge]: https://img.shields.io/badge/npm-6.14.4-red

[web_react_badge]: https://img.shields.io/badge/web-react-blue

[mobile_react-native_badge]: https://img.shields.io/badge/mobile-react%20native-blueviolet

[server_nodejs_badge]: https://img.shields.io/badge/server-nodejs-important

<!-- Techs -->

[react]: https://reactjs.org/

[typescript]: https://www.typescriptlang.org/

[node]: https://nodejs.org/en/

[leaflet]: https://react-leaflet.js.org/en/

[ibge_api]: https://servicodados.ibge.gov.br/api/docs/localidades?versao=1

[ibge_api_ufs]: https://servicodados.ibge.gov.br/api/docs/localidades?versao=1#api-UFs-estadosGet

[ibge_api_municipios]: https://servicodados.ibge.gov.br/api/docs/localidades?versao=1#api-Municipios-estadosUFMunicipiosGet

[vscode]: https://code.visualstudio.com/

### Functionality
[react_native]: http://www.reactnative.com/

- The API should follow typical RESTful API design pattern.
- The data should be saved in the DB.
- Provide proper API documentation.
- Proper error handling should be used.
[stackedit]: https://stackedit.io

## What We Care About
[vscode_sqlite_extension]: https://marketplace.visualstudio.com/items?itemName=alexcvzz.vscode-sqlite

Use any libraries that you would normally use if this were a real production App. Please note: we're interested in your code & the way you solve the problem, not how well you can use a particular library or feature.
[markdown_emoji]: https://gist.github.com/rxaviers/7360908

_We're interested in your method and how you approach the problem just as much as we're interested in the end result._
[commitlint]: https://github.com/conventional-changelog/commitlint

Here's what you should strive for:
[express]: https://expressjs.com/

- Good use of current Node.js & Express.js
- Good use of API design best practices.
- Solid testing approach.
- Extensible code.
[cors]: https://expressjs.com/en/resources/middleware/cors.html

## Implementation Path:
[knex]: http://knexjs.org/

### Basic Requirements
[sqlite3]: https://github.com/mapbox/node-sqlite3

- Use Node.js `LTS` and any framework of your choice.
- Use any SQL DB. MySQL DB is preferred.
- Write concise and clear commit messages.
- Write clear **documentation** on how it has been designed and how to run the code.
[tsnode]: https://github.com/TypeStrong/ts-node

### Bonus
- **Use typescript.**
- Use of Sequelize ORM (https://sequelize.org/)
- Provide proper unit tests.
- Add a read only endpoint to fetch location information based off the user's address (use [NASA](https://api.nasa.gov/api.html) or [Mapbox](https://www.mapbox.com/api-documentation/) APIs)
- Providing an online demo is welcomed, but not required.
[feather_icons]: https://feathericons.com/

## Q&A
[insomnia]: https://insomnia.rest/

> Where should I send back the result when I'm done?
[react_leaflet]: https://react-leaflet.js.org/

Fork this repo and send us a pull request when you think you are done. Or send me the link of the forked repo.
[react_router_dom]: https://github.com/ReactTraining/react-router/tree/master/packages/react-router-dom

> What if I have a question?
[react_icons]: https://react-icons.github.io/react-icons/

Create a new issue in this repo or send me an email.
[axios]: https://github.com/axios/axios
67 changes: 67 additions & 0 deletions README_instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Raks Back-end Developer Test

Be sure to read **all** of this document carefully, and follow the guidelines within.

## Context

Build a RESTful API that can `create/read/update/delete` user data from a persistence store.

### User Model

```
{
"id": "xxx", // user ID (must be unique)
"name": "backend test", // user name
"dob": "", // date of birth
"address": "", // user address
"description": "", // user description
"createdAt": "" // user created date
"updatedAt": "" // user updated date
}
```

### Functionality

- The API should follow typical RESTful API design pattern.
- The data should be saved in the DB.
- Provide proper API documentation.
- Proper error handling should be used.

## What We Care About

Use any libraries that you would normally use if this were a real production App. Please note: we're interested in your code & the way you solve the problem, not how well you can use a particular library or feature.

_We're interested in your method and how you approach the problem just as much as we're interested in the end result._

Here's what you should strive for:

- Good use of current Node.js & Express.js
- Good use of API design best practices.
- Solid testing approach.
- Extensible code.

## Implementation Path:

### Basic Requirements

- Use Node.js `LTS` and any framework of your choice.
- Use any SQL DB. MySQL DB is preferred.
- Write concise and clear commit messages.
- Write clear **documentation** on how it has been designed and how to run the code.

### Bonus
- **Use typescript.**
- Use of Sequelize ORM (https://sequelize.org/)
- Provide proper unit tests.
- Add a read only endpoint to fetch location information based off the user's address (use [NASA](https://api.nasa.gov/api.html) or [Mapbox](https://www.mapbox.com/api-documentation/) APIs)
- Providing an online demo is welcomed, but not required.

## Q&A

> Where should I send back the result when I'm done?

Fork this repo and send us a pull request when you think you are done. Or send me the link of the forked repo.

> What if I have a question?

Create a new issue in this repo or send me an email.
55 changes: 55 additions & 0 deletions __tests__/deleteUser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import User from "../src/models/user";
import { DeleteUser } from "../src/services/deleteUser";
import { SingUpService } from "../src/services/signUp"


const makeUserData = (): any => ({
body: {
name: 'any_name',
dob: 'any_dob',
address: 'any_address',
description: 'any_description',
}
})

describe('Delete User Service', () => {
test('Should return 400 if no id is provided ', async () => {
const sut = new DeleteUser()

const response = await sut.handle(makeUserData())

expect(response.statusCode).toBe(400)
})
test('Should return 200 valid data is provided',async () => {
const sut = new DeleteUser()
const singUpService = new SingUpService()

const httpResponse = await singUpService.handle(makeUserData())

const httpRequest = {
body: {
id: httpResponse.body.id
}
}

const response = await sut.handle(httpRequest)

expect(response.statusCode).toBe(200)
})
test('Should return 500 if sequelize return throws',async () => {
const sut = new DeleteUser()
const singUpService = new SingUpService()

const httpResponse = await singUpService.handle(makeUserData())

const httpRequest = {
body: {
id: httpResponse.body.id
}
}
jest.spyOn(User, 'destroy').mockReturnValueOnce(new Promise((resolve, reject) => reject(new Error())))
const response = await sut.handle(httpRequest)

expect(response.statusCode).toBe(500)
})
})
61 changes: 61 additions & 0 deletions __tests__/getUser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import User from "../src/models/user"
import { GetUser } from "../src/services/getUser"
import { SingUpService } from "../src/services/signUp"


const makeUserData = (): any => ({
body: {
name: 'any_name',
dob: 'any_dob',
address: 'any_address',
description: 'any_description',
}
})

describe('Get User Service', () => {
test('Should return 400 if no id is provided ', async () => {
const sut = new GetUser()

const response = await sut.handle(makeUserData())

expect(response.statusCode).toBe(400)
})
test('Should return 200 and data user is valid id is provided',async () => {
const sut = new GetUser()
const singUpService = new SingUpService()

const httpResponse = await singUpService.handle(makeUserData())

const httpRequest = {
body: {
id: httpResponse.body.id
}
}

const responseGetUser = await sut.handle(httpRequest)



expect(responseGetUser.statusCode).toBe(200)
expect(responseGetUser.body.name).toBe(httpResponse.body.name)
expect(responseGetUser.body.address).toBe(httpResponse.body.address)
expect(responseGetUser.body.description).toBe(httpResponse.body.description)

})
test('Should return 500 if sequelize return throws',async () => {
const sut = new GetUser()
const singUpService = new SingUpService()

const httpResponse = await singUpService.handle(makeUserData())

const httpRequest = {
body: {
id: httpResponse.body.id
}
}
jest.spyOn(User, 'findByPk').mockReturnValueOnce(new Promise((resolve, reject) => reject(new Error())))
const response = await sut.handle(httpRequest)

expect(response.statusCode).toBe(500)
})
})
6 changes: 6 additions & 0 deletions __tests__/jestSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const path = require('path')

const environment = process.env.NODE_ENV || 'test'
const envPath = path.join(__dirname, environment + '.env')

require('dotenv').config({ path: envPath })
Loading