A simple sample CRUD application to test using Keploy build with Node, JWT and Postgres.
Clone the repository and move to express-mongo folder
git clone https://github.com/keploy/samples-typescript && cd samples-typescript/node-jwt
# Install the dependencies
npm installLet's get started by setting up the Keploy alias with this command:
curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.shThere are 2 ways you can run this sample application.
docker-compose up -dsudo -E env PATH=$PATH keploy record -c 'node app.js'Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.
- Create User
curl --location 'http://localhost:8080/api/auth/signup' \
--header 'Content-Type: application/json' \
--data-raw '{
"username":"user",
"email":"user@keploy.io",
"password":"1234"
}'we will get the output:
{"message":"User was registered successfully!"}We will get the following output in our terminal
Let's go ahead create few more testcases for different endpoints!
- Create Admin User
curl --location 'http://localhost:8080/api/auth/signup' \
--header 'Content-Type: application/json' \
--data-raw '{
"username":"admin",
"email":"admin@keploy.io",
"password":"1234",
"role":["admin"]
}'we will get the output:
{"message":"User was registered successfully!"}- User Signin
curl --location 'http://localhost:8080/api/auth/signin' \
--header 'Content-Type: application/json' \
--data-raw '{
"username":"user",
"email":"user@keploy.io",
"password":"1234"
}'We will get access token once the user has signed in:
{
"id":1,
"username":"user",
"email":"user@keploy.io",
"roles":["ROLE_USER"],
"accessToken":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNzEzNzY0ODY1LCJleHAiOjE3MTM3NjUwNDV9.5LSU1A1jxIbIQFS6Tq26ENNWZBinFt2cJQZ7swpipbc"}- Access user Content
curl --location 'http://localhost:8080/api/test/all'We will get:
Public Content
- Access user Content
curl --location 'http://localhost:8080/api/test/user' \
--header 'x-access-token: <TOKEN>'We will get
User Content
sudo -E env PATH=$PATH keploy test -c 'npm run app.js' --delay 10Our testcases will fail as the Token will generated again when we are using testmode.
Let's add the Etag and accessToken as the noise in the test-3.yml on line 45 under header.Date. The file would look like:-
noise:
| - header.Date
| - header.Etag
| - body.accessToken
Now, let's run the keploy in test mode again:-
Voila!! Our testcases has passed 🌟
Since we have setup our sample-app using docker, we need to update the postgres host on line 2, in config/db.config.js, from localhost to postgres.
We will run the keploy in record mode with docker-compose to start our application:-
keploy record -c "docker-compose up" --containerName "jwtSqlApp"Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.
- Create User
curl --location 'http://localhost:8080/api/auth/signup' \
--header 'Content-Type: application/json' \
--data-raw '{
"username":"user",
"email":"user@keploy.io",
"password":"1234"
}'we will get the output:
{"message":"User was registered successfully!"}We will get the following output in our terminal
Let's go ahead create few more testcases for different endpoints!
- Create Admin User
curl --location 'http://localhost:8080/api/auth/signup' \
--header 'Content-Type: application/json' \
--data-raw '{
"username":"admin",
"email":"admin@keploy.io",
"password":"1234",
"role":["admin"]
}'we will get the output:
{"message":"User was registered successfully!"}- User Signin
curl --location 'http://localhost:8080/api/auth/signin' \
--header 'Content-Type: application/json' \
--data-raw '{
"username":"user",
"email":"user@keploy.io",
"password":"1234"
}'We will get access token once the user has signed in:
{
"id":1,
"username":"user",
"email":"user@keploy.io",
"roles":["ROLE_USER"],
"accessToken":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNzEzNzY0ODY1LCJleHAiOjE3MTM3NjUwNDV9.5LSU1A1jxIbIQFS6Tq26ENNWZBinFt2cJQZ7swpipbc"}- Access user Content
curl --location 'http://localhost:8080/api/test/all'We will get:
Public Content
- Access user Content
curl --location 'http://localhost:8080/api/test/user' \
--header 'x-access-token: <TOKEN>'We will get
User Content
keploy test -c 'sudo docker-compose up' --containerName "jwtSqlApp" --delay 10Our testcases will fail as the Token will generated again when we are using testmode.
Let's add the Etag and accessToken as the noise in the test-3.yml on line 45 under header.Date. The file would look like:-
noise:
| - header.Date
| - header.Etag
| - body.accessToken
Now, let's run the keploy in test mode again:-
Voila!! Our testcases has passed 🌟



