A sample App using Typescript and using nhost.io as Backend as a service
- Clone the repository and move to ts-nhost folder
- Create a .env file which should contain HASURA_ADMIN_SECRET and GRAPHQL_ENDPOINT(as mentioned in ts-nhost/sample.env)
- -> Go to https://nhost.io/
- -> Sign Up/Sign In and create new project
- -> Go to Hasura Console and open Hasura
- -> Get the x-hasura-admin-secret and GraphQL Endpoint and name them as HASURA_ADMIN_SECRET and GRAPHQL_ENDPOINT respectively in .env
git clone https://github.com/keploy/samples-typescript && cd samples-typescript/ts-nhost
# Install the dependencies
npm install
Let'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.sh
There are 2 ways you can run this sample application.
-
Install required packages:
sudo apt-get install -y --no-install-recommends ca-certificates curl
This command installs necessary packages without additional recommended packages.
-
Download CA certificate:
curl -o ca.crt https://raw.githubusercontent.com/keploy/keploy/main/pkg/core/proxy/asset/ca.crt
This command downloads the CA certificate to
ca.crt
. -
Download setup script:
curl -o setup_ca.sh https://raw.githubusercontent.com/keploy/keploy/main/pkg/core/proxy/asset/setup_ca.sh
This command downloads the setup script to
setup_ca.sh
. -
Make the setup script executable:
chmod +x setup_ca.sh
This command changes the permissions of
setup_ca.sh
to make it executable. -
Run the setup script:
source ./setup_ca.sh
This command executes the setup script in the current shell.
- Start recording tests:
sudo -E env "PATH=$PATH" keploybin record -c 'ts-node src/app.ts'
Make API Calls using Hoppscotch, Postman or cURL command. Keploy will capture those calls to generate test suites containing test cases and data mocks.
-
Refer to ts-nhost/api.txt to make api calls.
-
Observe terminal output: Let's go ahead and create a few more test cases for different endpoints!
-
Start the application:
ts-node src/app.ts
-
Run the recorded tests:
sudo -E env "PATH=$PATH" keploybin test -c 'ts-node src/app.ts' --delay 10
-
Observe test run results: Voila!! Our test cases have passed 🌟
Since we have to setup our app using docker(make sure your docker is running)
docker network create keploy-network
We will run the keploy in record mode with docker-compose to start our application:-
keploy record -c "sudo docker-compose up" --containerName "ts-nhost"
Make API Calls using Hoppscotch, Postman or curl command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.
- Refer to ts-nhost/api.txt to make api calls
keploy test -c 'sudo docker-compose up' --containerName "ts-nhost" --delay 10
Voila!! Our testcases has passed 🌟