- Jest
- REST API
- Login with JWT
Separei a lógica do servidor (aplicação) da parte de 'ouvir' porta para quando rodar os testes não precisar alocar nenhuma porta
Dentro de src/
;
app.js
=> lógica do servidor (aplicação)
server.js
=> alocar portas
routes.js
=> rotas da aplicação
https://jestjs.io/ Node.js unit tests, mocks, coverage, etc.
-
install jest
yarn add jest -D
-
Jest Init
yarn jest --init
-
configure your
jest.config.js
& create your test in tests/integration or _tests/unit -
run your tests
yarn test
NOTE: you should create your .env
file.
example;
DB_HOST=127.0.0.1
DB_USER=***
DB_PASS=***
DB_NAME=***
run yarn jest
and you can see the test coverage of your code.
You can see each file and line that need coverage accessing __tests__/coverage/lcov-report/index.html
- install;
yarn add supertest -D
https://www.edureka.co/community/77202/how-can-i-set-node-env-production-on-windows
yarn add sequelize pg
(I'm using PostgreSQL)
yarn add sequelize-cli -D
yarn sequelize init
create files config/config.json
& models/index.js
& the emptys folders migrations/
and seeders/
;
yarn sequelize migration:create --name=create-users
If you are using postgreSQL & pgAdmin;
Create a new database in PgAdmin
NOTE: you can change the username & password in src/config/database.js
and the database name must be the same name
yarn sequelize db:migrate
create tables in the database if they don't exist & update database
after create your table you can access in pgAdmin -> Databases -> 'your_database' -> Schemas -> public -> Tables
https://jestjs.io/ Node.js unit tests, mocks, coverage, etc.
É um ORM que facilita a gente lidar com os dados e tabelas do nosso Banco de Dados, utilizando sintaxe de Javascript
ao invés de SQL
.
lib para o sequelize lidar com o Banco de Dados PostgreSQL
ajuda a lidar com a criação das migrations, que são os arquivos que vão controlar a versão das nossas tabelas do BD
https://www.youtube.com/watch?v=2G_mWfG0DZE&list=PLmX5_ydv5jg-WRtaCb72IbYiuYvIacooR&index=5&t=1240s