Auth sample with JWT using express, prisma, jest, and supertest.
This project has a sql3 database on folder for study and tests.
Project have jest configured with coverage, for run execute: yarn test
Jest create folder named .coverage
with all issues for test coverage.
First install dependencies of project with yarn
Second run this command for execute local instance yarn dev
Now API running on http://localhost:3000/
For initial information using:
curl --request GET \
--url http://localhost:3000/
Using this request for authenticate:
curl --request POST \
--url http://localhost:3000/authenticate \
--header 'Content-Type: application/json' \
--data '{
"username": "[email protected]",
"password": "alicePWD"
}'
Have two users on database:
const users = [
{
email: '[email protected]',
password: 'alicePWD',
},
{
email: '[email protected]',
password: 'bobPWD',
},
]
Using this request for welcome, Authorization header is create with access_token from authenticate request:
curl --request GET \
--url http://localhost:3000/welcome \
--header 'Authorization: Bearer eyJhbGciOiJ...'
Now the tests are made using the sql3 database on local resource.
Upgrade code and test for using local database for testing, mock and others resources for prisma testing.
Prepare code for using .env values and other stuffs for production.