diff --git a/bun-mongo/README.md b/bun-mongo/README.md index 1050272..5269f3a 100644 --- a/bun-mongo/README.md +++ b/bun-mongo/README.md @@ -1,26 +1,30 @@ -# Sample app with Bun.js and MongoDb +# Sample app with Bun.js and MongoDB -This is a sample app to test Keploy integration capabilities using [Bun.js](https://bun.sh) and MongoDb. +This is a sample app to test Keploy integration capabilities using [Bun.js](https://bun.sh) and MongoDB. -## Pre-requsite -We first need to install bun.js. -```zsh +## Prerequisite + +We first need to install bun.js. + +```bash # Bun.js is supported on macOS, Linux, and WSL curl -fsSL https://bun.sh/install | bash ``` + ## Setup app Now that we have bun installed, we will setup our application -```zsh + +```bash git clone https://github.com/keploy/samples-typescript && cd samples-typescript/bun-mongo # Install the dependencies bun install ``` -# Using Keploy : +# Using Keploy -There are two ways to use Keploy:- +There are two ways to use Keploy:- 1. [Natively on Linux/WSL](#natively-on-ubuntuwsl) 2. [Using Docker](#running-sample-app-using-docker) @@ -30,22 +34,24 @@ There are two ways to use Keploy:- Keploy can be installed on Linux directly and on Windows with the help of WSL. Based on your system architecture, install the keploy latest binary release from here:- #### Linux + 1. AMD Architecture -```zsh + +```bash curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp -sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy +sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy --version ``` -
+
2. ARM Architecture - -```zsh +```bash curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz" | tar xz -C /tmp -sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy +sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy --version ``` +
#### Windows Subsystem for Linux (WSL) @@ -55,16 +61,18 @@ On Windows, WSL is required to run Keploy Binary. You must be running Windows 10 ```bash wsl --install ``` + Once installed download and Install "Keploy Binary" : ```bash curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp -sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy +sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy --version ``` ### Let's start the MongoDB Instance -```zsh + +```bash docker-compose up -d mongo ``` @@ -73,12 +81,13 @@ docker-compose up -d mongo ### Capture the testcases ```bash -sudo -E env PATH=$PATH Keploy record -c 'bun run supabun.ts' +sudo -E env PATH=$PATH keploy record -c 'bun run supabun.ts' ``` -Make API Calls using [Hoppscotch](https://hoppscotch.io), [Postman](https://postman.com) or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. +Make API Calls using [Hoppscotch](https://hoppscotch.io), [Postman](https://postman.com) or cURL command. Keploy will capture those calls to generate the test-suites containing testcases and data mocks. 1. Generate the testcases + ```bash curl --request POST localhost:4200/save ``` @@ -86,16 +95,18 @@ curl --request POST localhost:4200/save we will get the output: ``` -{"succes":true} +{"success":true} ``` -2. Fetch the data -```bash + +1. Fetch the data + +```json curl --request GET localhost:4200/fetch ``` this will provide us with the output:- ``` -{"succes":{"_id":"6513cfec0bc1a17a36c06337","name":"Cow","sound":"Moo","__v":0}} +{"success":{"_id":"6513cfec0bc1a17a36c06337","name":"Cow","sound":"Moo","__v":0}} ``` We will get the following output in our terminal @@ -108,57 +119,84 @@ We will get the following output in our terminal Keploy can be used on Linux & Windows through Docker, and on MacOS by the help of [Colima](https://docs.keploy.io/docs/server/macos/installation/#using-colima). ## Create Network (if it doesn't already exist) + This creates a new docker network isolated from others (named keploy-network) + ```bash docker network create keploy-network ``` ## Create Keploy Alias + Now, we need create an alias for Keploy: + ```bash alias keploy='sudo docker run --pull always --name keploy-v2 --network keploy-network -p 16789:16789 --privileged --pid=host -it -v $(pwd):$(pwd) -w $(pwd) -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm ghcr.io/keploy/keploy' ``` ## Let's start the MongoDB Instance + ```bash docker-compose up -d ``` +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. + ## Capture the testcases + 1. We first need to build dockerimage of our application:- + ```bash docker build -t bun-app:1.0 . ``` -2. Now we will run the keploy in record mode:- +1. Now we will run the keploy in record mode:- + ```bash -keploy record -c "docker run -p 420:420 --name bunMongoApp --network keploy-network bun-app:1.0" +keploy record -c "docker run -p 4200:4200 --name bunMongoApp --network keploy-network bun-app:1.0" ``` ### Let's generate the testcases. -Make API Calls using [Hoppscotch](https://hoppscotch.io), [Postman](https://postman.com) or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. + +Make API Calls using [Hoppscotch](https://hoppscotch.io), [Postman](https://postman.com) or cURL command. Keploy will capture those calls to generate the test-suites containing testcases and data mocks. + ```bash -curl --request POST localhost:420/save +curl --request POST localhost:4200/save ``` we will get the output: ``` -{"succes":true} +{"success": true} ``` + 2. Fetch the data + ```bash -curl --request GET localhost:420/fetch +curl --request GET localhost:4200/fetch ``` this will provide us with the output:- + ``` -{"succes":{"_id":"6513cfec0bc1a17a36c06337","name":"Cow","sound":"Moo","__v":0}} +{"success": {"_id":"6513cfec0bc1a17a36c06337","name":"Cow","sound":"Moo","__v":0}} ``` + We will get the following output in our terminal ![Testcase](./img/testcase-bun.png) # Running the testcases -This is WIP and depended upon the issue by oven/bun & elysia:- https://github.com/elysiajs/elysia/issues/231 +This is a Work-in-Progress(WIP) and depends on this issue by oven/bun & elysia:- https://github.com/elysiajs/elysia/issues/231 diff --git a/crud-node-mongo/README.md b/crud-node-mongo/README.md index 0623fa6..005dfec 100644 --- a/crud-node-mongo/README.md +++ b/crud-node-mongo/README.md @@ -1,6 +1,10 @@ # Hotel Management Web App + +This is a sample Hotel Management application used to demonstrate Keploy's capabilities for capturing and replaying API tests. + 1. **Node.js (version 14 or later):** Download and install it from [https://nodejs.org/en](https://nodejs.org/en). 2. **npm (version 5.6 or later):** This usually comes bundled with Node.js. Verify by running `npm -v` in your terminal. +3. **Docker:** Required to run the MongoDB instance. **1. Clone the Repository and Install Dependencies:** @@ -12,12 +16,13 @@ npm install **2. Run the Development Server:** Run the following command to launch the development server: -```Bash +```bash npm run dev ``` + # Different Jest Api Test cases -## Test Case 1: Book a Room +## Test Case 1: View Bookings ```javascript @@ -35,7 +40,7 @@ test('View Bookings - Success', async () => { }); expect(response.status).toBe(200); - expect(response.data.bookings.lenQgth).toBeGreaterThan(0); // Adjusted expectation + expect(response.data.bookings.length).toBeGreaterThan(0); // Adjusted expectation }); @@ -43,7 +48,7 @@ test('View Bookings - Success', async () => { ## Test Case 2: Edit a Booking -```bash +```javascript test('Edit a Booking - Success', async () => { const requestBody = { userEmail: "new_email@example.com", @@ -52,7 +57,7 @@ test('Edit a Booking - Success', async () => { endTime: "2024-04-23T11:00:00Z" }; - const response = await axios.put('http://your-api-url/edit/', requestBody, { + const response = await axios.put('http://localhost:3000/edit/{id}', requestBody, { headers: { 'Content-Type': 'application/json' } @@ -66,9 +71,9 @@ test('Edit a Booking - Success', async () => { ## Test Case 3: Cancel a Booking -```bash +```javascript test('Cancel a Booking - Success', async () => { - const response = await axios.delete('http://your-api-url/cancel/', { + const response = await axios.delete('http://localhost:3000/cancel/{id}', { headers: { 'Content-Type': 'application/json' } @@ -77,14 +82,13 @@ test('Cancel a Booking - Success', async () => { expect(response.status).toBe(200); expect(response.data.message).toEqual("Booking cancelled successfully"); }); - ``` -## Test Case 4: View Bookings +## Test Case 4: View Bookings -```bash +```javascript test('View Bookings - Success', async () => { - const response = await axios.get('http://your-api-url/view', { + const response = await axios.get('http://localhost:3000/bookings/view', { headers: { 'Content-Type': 'application/json' }, @@ -111,19 +115,34 @@ On Windows, WSL is required to run Keploy Binary. ```bash wsl --install ``` + Once installed download and Install "Keploy Binary" : ```bash curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp -sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy +sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy --version ``` ### Let's start the MongoDB Instance -```zsh + +```bash docker-compose up -d ``` +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. + > **Since we have setup our sample-app natively, we need to update the mongoDB host on line 41, in `db/connection.js`, from `mongodb://mongoDb:27017/Students` to `mongodb://127.0.0.1:27017/keploy`.** ### Capture the testcases @@ -132,19 +151,17 @@ docker-compose up -d sudo -E env PATH=$PATH keploy record -c 'node src/app.js' ``` - -## we will get the output: +## we will get the output ![Testcase](./img/p1.jpg) ## Running the testcases - ```bash -keploy test -c "CMD_TO_RUN_APP" --delay 10 - +sudo -E env PATH=$PATH keploy test -c 'node src/app.js' --delay 10 ``` + ![Testcase](./img/p2.jpg) ![Testcase](./img/p3.jpg) diff --git a/express-mongodb/Readme.md b/express-mongodb/Readme.md index fb86b5c..3195112 100644 --- a/express-mongodb/Readme.md +++ b/express-mongodb/Readme.md @@ -1,59 +1,103 @@ -# CRUD API +# CRUD API with Keploy -This is a simple RESTful API for managing products. It provides endpoints for basic CRUD (Create, Read, Update, Delete) operations on products. +This is a simple RESTful API for managing products. It provides endpoints for basic CRUD (Create, Read, Update, Delete) operations and is integrated with [Keploy](https://keploy.io) to demonstrate automated test case and mock generation. + +--- ## Features -- Create Product: Add a new product to the database. -- Read Product: Retrieve information about a specific product or get a list of all products. -- Update Product: Modify the details of an existing product. -- Delete Product: Remove a product from the database. +- **Create Product**: Add a new product to the database. +- **Read Product**: Retrieve a specific product or list all products. +- **Update Product**: Modify the details of an existing product. +- **Delete Product**: Remove a product from the database. + +--- ## Technologies Used -- Node.js: JavaScript runtime environment. -- Express.js: Web application framework for Node.js. -- MongoDB: NoSQL database for storing product data. -- Mongoose: MongoDB object modeling for Node.js. +- **Node.js**: JavaScript runtime environment. +- **Express.js**: Web application framework for Node.js. +- **MongoDB**: NoSQL database for storing product data. +- **Mongoose**: MongoDB object modeling for Node.js. +- **Keploy**: Tool for automated API testing and dependency mocking. + +--- ## Getting Started ### Prerequisites -- Node.js installed on your machine -- MongoDB installed and running locally or on a remote server +- **Node.js** installed on your machine. +- **MongoDB** installed and running locally or via Docker. +- **Keploy Binary** (required to record and run tests). + +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. -## Installation +### Installation -1. Clone the repository
+1. Clone the Repository ```bash -git clone https://github.com//crud-API.git +git clone https://github.com/keploy/samples-typescript +cd samples-typescript/crud-API ``` -2. Install dependencies
+2. Install Dependencies ```bash -cd crud-API npm install ``` -3. Start the server
+3. Install Keploy(Linux/WSL) ```bash -npm run dev +curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp +sudo mkdir -p /usr/local/bin +sudo mv /tmp/keploy /usr/local/bin +keploy --version ``` -## Endpoints +4. Start MongoDB Instance -- GET /products: Fetch all products. -- GET /products/:id: Fetch a product by ID. -- POST /products: Create a new product. -- PUT /products/:id: Update a product by ID. -- DELETE /products/:id: Delete a product by ID. +Ensure MongoDB is running. If you have Docker, you can start a container: +```bash +docker run -p 27017:27017 --name mongodb -d mongo +``` + +### Keploy Test Workflow + +1. Capture Test Cases (Record Mode) + +Run the application through Keploy to capture API calls and generate test suites: +```bash +sudo -E env PATH=$PATH keploy record -c "npm run dev" +``` + +2. Run Test Cases (Test Mode) +Stop the application and run the recorded tests to verify behavior: +```bash +sudo -E env PATH=$PATH keploy test -c "npm run dev" --delay 10 +``` +### API Endpoints +•GET /products — Fetch all products +•GET /products/:id — Fetch a product by ID +•POST /products — Create a new product +•PUT /products/:id — Update a product by ID +•DELETE /products/:id — Delete a product by ID diff --git a/express-mongoose/README.md b/express-mongoose/README.md index 492c2e5..b8a5084 100644 --- a/express-mongoose/README.md +++ b/express-mongoose/README.md @@ -3,6 +3,7 @@ A simple sample CRUD application to test using Keploy build with Express and MongoDB. ## Install Keploy + Install keploy via one-click:- ```bash @@ -10,7 +11,9 @@ curl --silent -O -L https://keploy.io/install.sh && source install.sh ``` ## Setup application + Clone the repository and move to express-mongo folder + ```bash git clone https://github.com/keploy/samples-typescript && cd samples-typescript/express-mongoose @@ -19,10 +22,24 @@ npm install ``` ### Let's start the MongoDB Instance -```zsh + +```bash docker-compose up -d mongo ``` +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. + > **Since we have setup our sample-app natively, we need to update the mongoDB host on line 41, in `db/connection.js`, from `mongodb://mongoDb:27017/Students` to `mongodb://127.0.0.1:27017/keploy`.** ### Capture the testcases @@ -32,7 +49,8 @@ sudo -E env PATH=$PATH keploy record -c 'node src/app.js' ``` #### Let's generate the testcases. -Make API Calls using [Hoppscotch](https://hoppscotch.io), [Postman](https://postman.com) or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. + +Make API Calls using [Hoppscotch](https://hoppscotch.io), [Postman](https://postman.com) or cURL command. Keploy will capture those calls to generate the test-suites containing testcases and data mocks. ```bash curl --request POST \ @@ -58,7 +76,7 @@ We will get the following output in our terminal ## Running the testcases ```bash -sudo -E env PATH=$PATH keploy test -c 'npm run src/app.js' --delay 10 +sudo -E env PATH=$PATH keploy test -c 'node src/app.js' --delay 10 ``` Our testcases will fail as the Keep-Alive connection won't be available when we are using testmode, this happen because in test mode the Keploy uses the `Mocks.yml`, which was generated in the record mode. @@ -86,19 +104,23 @@ Now, let's run the keploy in test mode again:- Keploy can be used on Linux & Windows through Docker, and on MacOS by the help of [Colima](https://docs.keploy.io/docs/server/macos/installation/#using-colima). ## Create Keploy Alias + We need create an alias for Keploy: + ```bash alias keploy='sudo docker run --pull always --name keploy-v2 -p 16789:16789 --privileged --pid=host -it -v $(pwd):$(pwd) -w $(pwd) -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock --rm ghcr.io/keploy/keploy' ``` ## Capture the testcases - + We will run the keploy in record mode with docker-compose to start our application:- + ```bash keploy record -c "docker compose up" --containerName "nodeMongoApp" ``` #### Let's generate the testcases. + Make API Calls using [Hoppscotch](https://hoppscotch.io), [Postman](https://postman.com) or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. ```bash @@ -122,11 +144,10 @@ We will get the following output in our terminal ![Testcase](./img/testcase-node.png) - ## Running the testcases ```bash -keploy test -c "docker compose up --node-app" --containerName "nodeMongoApp" --delay 10 +keploy test -c "docker compose up node-app" --containerName "nodeMongoApp" --delay 10 ``` Our testcases will fail as the Keep-Alive connection won't be available when we are using testmode, this happen because in test mode the Keploy uses the `Mocks.yml`, which was generated in the record mode. @@ -149,7 +170,7 @@ Now, let's run the keploy in test mode again:- ## Create Unit Testcase with Keploy -### Prequiste +### Prerequisite AI model API_KEY to use: - OpenAI's GPT-4o. @@ -177,7 +198,11 @@ We got around 31.5% of code coverage. Now, let's run keploy to create testcases. ```bash -keploy gen --sourceFilePath="/home/sonichigi.linux/samples-typescript/express-mongoose/src/routes/routes.js" --testFilePath="/home/sonichigi.linux/samples-typescript/express-mongoose/test/routes.test.js" --testCommand="npm test" --coverageReportPath="/home/sonichigi.linux/samples-typescript/express-mongoose/coverage/cobertura-coverage.xml" +keploy gen \ + --sourceFilePath="./src/routes/routes.js" \ + --testFilePath="./test/routes.test.js" \ + --testCommand="npm test" \ + --coverageReportPath="./coverage/cobertura-coverage.xml" ``` With the above command, Keploy will generate new testcases in the our `routes.test.js` and will increase code coverage upto 58%. diff --git a/express-postgresql-prisma/README.md b/express-postgresql-prisma/README.md index b690197..14c5a4c 100644 --- a/express-postgresql-prisma/README.md +++ b/express-postgresql-prisma/README.md @@ -6,11 +6,11 @@ This API manages personal or team tasks, built with Express, PostgreSQL, and Pri ## Features -- **ORM: Prisma** -- **Database: PostgreSQL** -- **RESTful routes for managing tasks** -- **Validation middleware** -- **Swagger documentation** +- **ORM**: Prisma +- **Database**: PostgreSQL +- **RESTful routes**: for managing tasks +- **Validation**: middleware for data integrity +- **Documentation**: Swagger/OpenAPI support ## Middlewares @@ -29,6 +29,21 @@ Ensure you have the following installed: - Node.js and npm - Keploy CLI +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. + +### 1. Setup Project + Clone the repository and move to express-postgresql-prisma folder ```bash @@ -36,18 +51,20 @@ git clone https://github.com/keploy/samples-typescript.git cd samples-typescript/express-postgresql-prisma ``` +### Install dependencies -### Install the dependencies ```bash npm install ``` -### Set up environment variables: +### Set up environment variables + ```bash cp .env.example .env ``` ### Start PostgreSQL Container + ```bash docker run --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres ``` @@ -60,10 +77,11 @@ docker run --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 PORT=3000 DATABASE_URL="postgresql://postgres:mysecretpassword@localhost:5432/postgres" ``` + > Note: If you are using Supabase, you need to add a DIRECT_URL to your .env file and uncomment the directUrl line in your prisma/schema.prisma file. +### Migrate the database -### Migrate the database: ```bash npm run generate npm run migrate init @@ -104,7 +122,8 @@ nt in 50ms └─────────────────────────────────────────────────────────┘ ``` -### Start the application: +### Start the application + ```bash npm run dev ``` @@ -118,8 +137,7 @@ Server is listening at PORT 3000 > Note: The application will run on `http://localhost:3000`. -Now we walkthrough how to leverage Keploy to automatically generate test cases for the application, and later test the application using Keploy. - +Now we walk through how to leverage Keploy to automatically generate and run test cases for the application. ### Generate Test Cases @@ -165,7 +183,6 @@ The above command will start recording the API calls made to the application and > 💡 You can use Postman or any other API testing tool to test the API calls. Additionally, the application will run a swagger UI on `http://localhost:3000/api/docs` to visualize the API calls. - ### Interact with Application Use Postman or Swagger to hit your API routes. This interaction will be recorded by Keploy. @@ -177,7 +194,6 @@ Use Postman or Swagger to hit your API routes. This interaction will be recorded #### Add Task - - **URL:** `/api/v1/task/add` - **Method:** `POST` - **Description:** Add a new task. @@ -194,6 +210,7 @@ Use Postman or Swagger to hit your API routes. This interaction will be recorded ``` Using `curl` + ```bash curl -X 'POST' \ 'http://localhost:3000/api/v1/task/add' \ @@ -209,26 +226,23 @@ curl -X 'POST' \ }' ``` - #### View All Tasks Using `curl` + ```bash curl -X 'GET' \ 'http://localhost:3000/api/v1/task/view' \ -H 'accept: application/json' ``` - #### View Task by ID - - **URL:** `/api/v1/task/view/:id` - **Method:** `GET` - **Description:** Retrieve a specific task by its ID. - **Request Params:** `id` (task ID) - Using `curl` ```bash @@ -237,7 +251,6 @@ curl -X 'GET' \ -H 'accept: application/json' ``` - #### Change Task Priority - **URL:** `/api/v1/task/change-priority/:id` @@ -245,6 +258,7 @@ curl -X 'GET' \ - **Description:** Update the priority of a specific task. - **Request Params:** `id` (task ID) - **Request Body:** + ```json { "priority": 3 @@ -252,6 +266,7 @@ curl -X 'GET' \ ``` Using `curl` + ```bash curl -X 'PUT' \ 'http://localhost:3000/api/v1/task/change-priority/1' \ @@ -269,6 +284,7 @@ curl -X 'PUT' \ - **Description:** Update details of a specific task. - **Request Params:** `id` (task ID) - **Request Body:** + ```json { "author": "John Doe", @@ -281,6 +297,7 @@ curl -X 'PUT' \ ``` Using `curl` + ```bash curl -X 'PUT' \ 'http://localhost:3000/api/v1/task/update/2' \ @@ -304,6 +321,7 @@ curl -X 'PUT' \ - **Request Params:** `id` (task ID) Using `curl` + ```bash curl -X 'DELETE' \ 'http://localhost:3000/api/v1/task/delete/1' \ @@ -312,61 +330,6 @@ curl -X 'DELETE' \ > 🐰 Test Data and Configuration: After recording the interactions, a `keploy` folder will be created containing the recorded test data. Additionally, a `keploy.yml` file will be created as the configuration file. -### - Add Task - - - -### - Update Task - -- **URL:** `/update/:id` -- **Method:** `PUT` -- **Description:** Update an existing task by ID. -- **Request Params:** `id` (task ID) -- **Request Body:** - ```json - { - "title": "Updated Task Title", - "description": "Updated Task Description", - "priority": 2 - } - ``` - -### - Delete Task - -- **URL:** `/delete/:id` -- **Method:** `DELETE` -- **Description:** Delete a task by ID. -- **Request Params:** `id` (task ID) - - -### - View All Tasks - -- **URL:** `/view` -- **Method:** `GET` -- **Description:** View all tasks. - - -### - View Task by ID - -- **URL:** `/view/:id` -- **Method:** `GET` -- **Description:** View a task by ID. -- **Request Params:** `id` (task ID) - - -### - Change Task Priority - -- **URL:** `/change-priority/:id` -- **Method:** `PUT` -- **Description:** Change the priority of a task by ID. -- **Request Params:** `id` (task ID) -- **Request Body:** - ```json - { - "priority": 3 - } - ``` - ### Test the Application using Keploy ```bash diff --git a/hono-prisma-postgres/README.md b/hono-prisma-postgres/README.md index 8008c83..626d9bc 100644 --- a/hono-prisma-postgres/README.md +++ b/hono-prisma-postgres/README.md @@ -84,9 +84,23 @@ There are two ways to run this application: #### Prerequisites -- Docker and Docker Compose installed +- Docker installed +- Docker Compose v2 installed - Keploy installed +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. + #### Steps to Run 1. **Create Docker Network** @@ -97,13 +111,10 @@ There are two ways to run this application: > **Note:** While this network should be created automatically during installation, this command ensures it exists. - ``` - - ``` - 2. **Start the Application** + ```bash - docker-compose up --build + docker compose up --build ``` ## Keploy Integration diff --git a/nestjs-drizzle-supabase/README.md b/nestjs-drizzle-supabase/README.md index 53ba3ce..ec68ef0 100644 --- a/nestjs-drizzle-supabase/README.md +++ b/nestjs-drizzle-supabase/README.md @@ -1,45 +1,68 @@ # NestJs + Drizzle +Supabase -Tech STack - +Tech Stack - + 1. NestJs 2. Postgres 3. Supabase 4. Drizzle -### To install the deoendencies +This is a sample application built with **NestJs**, **Drizzle ORM**, and **Supabase (Postgres)**, integrated with [Keploy](https://keploy.io) for automated test case and mock generation. + +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, Install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin ``` + +Then use `docker compose up` instead of `docker-compose up`. + +### To install the dependencies + +```bash npm install ``` -Create a .env +Create a .env file .env requires `DATABASE_URL` for the db ( we have used Postgres) -### Setup Drizzle MIgration -``` +### Setup Drizzle Migration + +```bash npm run generate ``` ### Start the app -``` + +```bash npm run start ``` ### To run tests(about 80% of test coverage until now) -``` + +```bash npm run test:cov ``` ### Postman Collection of routes + https://dark-sunset-197753.postman.co/workspace/My-Workspace~8503974e-6cc0-4f18-8a0e-1599701fd834/collection/33233997-092cc06c-24ae-40bd-8252-70f74c57abe8?action=share&creator=33233997 -### Keploy -Keploy helped generate test cases on various yaml files +### Keploy -``` +Keploy helped generate test cases on various YAML files + +```bash keploy record -c "npm run start" ``` -#### create test cases using - -``` +#### Create test cases using + +```bash keploy test -c "npm run start" --delay 10 ``` diff --git a/nextjs-postgres/README.md b/nextjs-postgres/README.md index 1432027..8ad53df 100644 --- a/nextjs-postgres/README.md +++ b/nextjs-postgres/README.md @@ -1,9 +1,24 @@ # Node-Postgres -A simple User management application to test using Keploy build with NextJS and Postgres. +A simple User management application to test using Keploy built with Next.js and Postgres. + +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. ## Setup application -Clone the repository and move to express-mongo folder + +Clone the repository and move to nextjs-postgres folder + ```bash git clone https://github.com/keploy/samples-typescript && cd samples-typescript/nextjs-postgres @@ -12,9 +27,11 @@ npm install ``` Keploy can be installed on Linux directly and on Windows with the help of WSL. Based on your system architecture, install the keploy latest binary release from here:- -### Let's start the MongoDB Instance -```zsh -docker-compose up -d + +### Start the PostgreSQL Database + +```bash +docker compose up -d ``` ### Capture the testcases @@ -24,6 +41,7 @@ sudo -E env PATH=$PATH keploy record -c 'npm run dev' ``` #### Let's generate the testcases. + Make API Calls using [Hoppscotch](https://hoppscotch.io), [Postman](https://postman.com) or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. ```bash @@ -46,19 +64,19 @@ we will get the output: Let's go ahead and create some more API Requests! -2. Get Users +1. Get Users ```bash curl -X GET http://localhost:3000/api/users ``` -3. Update Users +2. Update Users ```bash curl -X PUT -H "Content-Type: application/json" -d '{"id":1,"name":"John Deo","email":"updated@example.com"}' http://localhost:3000/api/users ``` -4. Delete Users +3. Delete Users ```bash curl -X DELETE -H "Content-Type: application/json" -d '{"id":1}' http://localhost:3000/api/users @@ -66,7 +84,6 @@ curl -X DELETE -H "Content-Type: application/json" -d '{"id":1}' http://localhos ![TestCase](./img/record.png) - ## Running the testcases ```bash @@ -75,4 +92,4 @@ sudo -E env PATH=$PATH keploy test -c 'npm run dev' --delay 10 ![Testrun](./img/test.png) -*Voila!! Our testcases has passed 🌟* \ No newline at end of file +*Voila! Our test cases have passed 🌟 diff --git a/node-bigpayload/Readme.md b/node-bigpayload/Readme.md index 0f27b48..082c449 100644 --- a/node-bigpayload/Readme.md +++ b/node-bigpayload/Readme.md @@ -20,6 +20,19 @@ You will need the following software installed on your system: - **Node.js**: Version 18.x or higher. You can download it from [nodejs.org](https://nodejs.org/). - **npm** (Node Package Manager): This is included with the Node.js installation. +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. + ### Installation 1. **Clone the repository** (or download the source code) to your local machine. @@ -42,8 +55,8 @@ You will need the following software installed on your system: Once the dependencies are installed, you can start the server with the following command: ```bash - -sudo -E env PATH=$PATH usr/local/bin/keploy record -c "node server.js" --bigRequest +sudo -E env PATH=$PATH /usr/local/bin/keploy record -c "node server.js" --bigRequest +``` (You can remove --bigRequest to record it for smaller size payloads) @@ -53,27 +66,40 @@ You should see a confirmation message in your terminal indicating that the serve The API is now live and ready to accept requests. -🧪 Testing the Endpoints +## 🧪 Testing the Endpoints + You can use a tool like curl or any API client (like Postman or Insomnia) to test the endpoints. -Small Payload (10KB) +### Small Payload (10KB) + # Make a request to the endpoint + +```bash curl http://localhost:3000/small-payload +``` # Verify the size of the response (should be 10240 bytes) + +```bash curl -s http://localhost:3000/small-payload | wc -c +``` + +### Large Payload (500KB) -Large Payload (500KB) # Make a request to the endpoint (output will be large) + +```bash curl http://localhost:3000/large-payload +``` # Verify the size of the response (should be 512000 bytes) -curl -s http://localhost:3000/large-payload | wc -c +```bash +curl -s http://localhost:3000/large-payload | wc -c ``` ## Run test using Keploy ```bash -sudo -E env PATH=$PATH usr/local/bin/keploy record -c "node server.js" &> testlogs.txt -``` \ No newline at end of file +sudo -E env PATH=$PATH keploy test -c "node server.js" --delay 10 &> testlogs.txt +``` diff --git a/node-jwt/README.md b/node-jwt/README.md index 969f6d6..e327e57 100644 --- a/node-jwt/README.md +++ b/node-jwt/README.md @@ -2,20 +2,42 @@ A simple sample CRUD application to test using Keploy build with Node, JWT and Postgres. +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. + ## Setup application + Clone the repository and move to express-mongo folder + ```bash git clone https://github.com/keploy/samples-typescript && cd samples-typescript/node-jwt +``` # Install the dependencies + +```bash npm install ``` + # Installing Keploy + Let's get started by setting up the Keploy alias with this command: -```sh + +```bash curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh ``` -## Using Keploy : + +## Using Keploy There are 2 ways you can run this sample application. @@ -24,12 +46,10 @@ There are 2 ways you can run this sample application. # Natively on Ubuntu/WSL - - - ## Let's start the Postgres Instance -```zsh -docker-compose up -d + +```bash +docker compose up -d ``` ## Capture the testcases @@ -38,7 +58,10 @@ docker-compose up -d sudo -E env PATH=$PATH keploy record -c 'node app.js' ``` -### Let's Generate the testcases. +# Note: sudo -E is used to preserve PATH so that keploy command works correctly. + +### Let's Generate the testcases + Make API Calls using [Hoppscotch](https://hoppscotch.io), [Postman](https://postman.com) or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. 1. Create User @@ -63,7 +86,7 @@ We will get the following output in our terminal ![Testcase](./img/record.png) -Let's go ahead create few more testcases for different endpoints! +Let's go ahead and create few more testcases for different endpoints! 2. Create Admin User @@ -85,6 +108,7 @@ we will get the output: ``` 3. User Signin + ```bash curl --location 'http://localhost:8080/api/auth/signin' \ --header 'Content-Type: application/json' \ @@ -96,6 +120,7 @@ curl --location 'http://localhost:8080/api/auth/signin' \ ``` We will get access token once the user has signed in: + ```json { "id":1, @@ -105,37 +130,43 @@ We will get access token once the user has signed in: "accessToken":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNzEzNzY0ODY1LCJleHAiOjE3MTM3NjUwNDV9.5LSU1A1jxIbIQFS6Tq26ENNWZBinFt2cJQZ7swpipbc"} ``` -4. Access user Content -```sh +1. Access user Content + +```bash curl --location 'http://localhost:8080/api/test/all' ``` We will get: + ``` Public Content ``` -5. Access user Content -```sh +1. Access user Content + +```bash curl --location 'http://localhost:8080/api/test/user' \ --header 'x-access-token: ' ``` We will get + ``` User Content ``` + ## Running the testcases ```bash sudo -E env PATH=$PATH keploy test -c 'npm run app.js' --delay 10 ``` -Our testcases will fail as the Token will generated again when we are using testmode. +Our testcases will fail because the Token will generated again when we are using testmode. ![Testcase](./img/test-fail.png) 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 @@ -158,11 +189,13 @@ Since we have setup our sample-app using docker, we need to update the postgres ## Capture the testcases We will run the keploy in record mode with docker-compose to start our application:- + ```bash -keploy record -c "docker-compose up" --containerName "jwtSqlApp" +keploy record -c "docker compose up" --containerName "jwtSqlApp" ``` #### Let's generate the testcases. + Make API Calls using [Hoppscotch](https://hoppscotch.io), [Postman](https://postman.com) or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks. 1. Create User @@ -209,6 +242,7 @@ we will get the output: ``` 3. User Signin + ```bash curl --location 'http://localhost:8080/api/auth/signin' \ --header 'Content-Type: application/json' \ @@ -220,6 +254,7 @@ curl --location 'http://localhost:8080/api/auth/signin' \ ``` We will get access token once the user has signed in: + ```json { "id":1, @@ -229,37 +264,43 @@ We will get access token once the user has signed in: "accessToken":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaWF0IjoxNzEzNzY0ODY1LCJleHAiOjE3MTM3NjUwNDV9.5LSU1A1jxIbIQFS6Tq26ENNWZBinFt2cJQZ7swpipbc"} ``` -4. Access user Content -```sh +1. Access user Content + +```bash curl --location 'http://localhost:8080/api/test/all' ``` We will get: + ``` Public Content ``` -5. Access user Content -```sh +1. Access user Content + +```bash curl --location 'http://localhost:8080/api/test/user' \ --header 'x-access-token: ' ``` We will get + ``` User Content ``` + ## Running the testcases ```bash keploy test -c 'sudo docker-compose up' --containerName "jwtSqlApp" --delay 10 ``` -Our testcases will fail as the Token will generated again when we are using testmode. +Our testcases will fail as the Token will be generated again when we are using testmode. ![Testcase](./img/test-fail.png) 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 @@ -271,4 +312,4 @@ Now, let's run the keploy in test mode again:- ![Testrun](./img/test-pass.png) -*Voila!! Our testcases has passed 🌟* \ No newline at end of file +*Voila!! Our test cases have passed 🌟* diff --git a/node-mongoose/readme.md b/node-mongoose/readme.md index 1e02769..3994daa 100644 --- a/node-mongoose/readme.md +++ b/node-mongoose/readme.md @@ -1,22 +1,35 @@ - ## COURSE SELLING API -This is an application to create online courses also with that you can update,delete and view your courses . +This is an application to create online courses, and also update, delete, or view them. ## Technologies Used + - Node.js - Express.js - MongoDB - Mongoose +## Quick Note: If you face any difficulty, refer to the following link. -## Quick Note If you face any difficulty refer to the given link ```bash Docs Link : https://keploy.io/blog/community/getting-started-with-keploy ``` ## Get Started! 🎬 +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. + **1. Clone the repository and move to express-mongoose-Sahil :** Run the following command to start the application: @@ -30,57 +43,78 @@ npm install **2. Run the Development Server:** Run the following command to start the application: -```Bash -node server.js +```bash +npm start ``` -### Docker installation and running the mongodb compass +### Docker Installation & MongoDB Compass **1. Install docker in your windows and follow this tutorial to connect with mongodb compass :** -``` bash + +``` https://www.youtube.com/watch?v=NEPZqSvKx40&list=PLff_PESolMjuDXQdjiqYRW_GnDQjU32QX ``` -**2. after installing docker and running those commands in video use this command as well to create a network:** +# Pull the MongoDB image + +```bash +docker pull mongo +``` + +# Run MongoDB container with port 27023 mapping + +```bash +docker run --name mongo-db -p 27023:27017 -d mongo +``` + +**2. After installing Docker and following the video commands, run the following to create a network:** + ```bash docker network create keploy-network ``` -> **url should look something like this depending on your connection you can adjust, also update your .env file with mongodb_url:`mongodb://127.0.0.1:27023/courses`.* +> **The URL may vary depending on your connection. Also, update your .env file with MONGODB_URL::`mongodb://127.0.0.1:27023/courses`.* +## Keploy Installation -## keploy installation +On Windows, WSL is required to run Keploy Binary. -On Windows, WSL is required to run Keploy Binary. +# Install Keploy Binary ```bash wsl --install ``` +```bash +curl --silent --location "https://get.keploy.io" | bash +``` + ### Capture the testcases in keploy ```bash sudo -E env PATH=$PATH keploy record -c 'npm start' ``` + ## Running the testcases ```bash -keploy -E env PATH=$PATH keploy test -c 'npm start' --delay 10 +sudo -E env PATH=$PATH keploy test -c 'npm start' --delay 10 ``` -### Api endpoints +### API Endpoints + - GET http://localhost:3000/courses - to get all courses. -- POST http://localhost:3000/courses - to post courses . +- POST http://localhost:3000/courses - to post courses. - DELETE http://localhost:3000/courses/:id - to delete a specific course. -- PUT http://localhost:3000/courses/:id - to update any course. +- PUT http://localhost:3000/courses/:id - to update a specific course. -jest test coverage report : +jest test coverage report : ![Screenshot 2024-04-22 025850](https://github.com/s2ahil/samples-typescript/assets/101473078/f60570d0-b998-4b4a-912d-80d4c73604e3) -postman tests: +postman tests: ![Screenshot 2024-04-22 031914](https://github.com/s2ahil/samples-typescript/assets/101473078/1ee5850e-3d31-46bd-bb5e-f842e5262cdd) Keploy test report: diff --git a/redis-express/README.md b/redis-express/README.md index 68f2df1..6e3754a 100644 --- a/redis-express/README.md +++ b/redis-express/README.md @@ -3,7 +3,7 @@ ## Overview -This API manages books record, built with Express and Redis. It provides routes to add, update, delete, view books, view books by ID, and change task authors. +This API manages book records, built with Express and Redis. It provides routes to add, update, delete, view books, view books by ID, and change task authors. ## Installation @@ -15,12 +15,25 @@ Ensure you have the following installed: - Node.js and npm - Keploy CLI +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. + # Installing Keploy Let's get started by setting up the Keploy alias with this command: -```sh -curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh +```bash +curl --silent -O -L https://keploy.io/install.sh && source install.sh ``` Clone the repository and move to express-redis folder @@ -29,14 +42,17 @@ Clone the repository and move to express-redis folder git clone https://github.com/keploy/samples-typescript.git cd samples-typescript/express-redis ``` + ## Installing Locally ### Install the dependencies + ```bash npm install ``` ### Start Redis-server Container + ```bash docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latest ``` @@ -63,29 +79,26 @@ port: 6379 ``` ### Build the application: + ```bash npm install npm run build ``` -### Start the application: -```bash -npm run start -``` +### Start the application +Note: Do not start the application manually; Keploy will start it for you during the recording process. > redis-ts@1.0.0 start > node dist/index.js - ```bash Server is running on http://localhost:3000 Connected to Redis server Sample books loaded into Redis ``` -Some sample data is automatically created in redis. - +Some sample data is automatically created in Redis. ## Using Docker @@ -100,25 +113,26 @@ docker compose up ### Generate Test Cases For server running locally. + ```bash -keploy record -c "npm run start" +sudo -E env PATH=$PATH keploy record -c "npm run start" ``` For the docker container. ```bash -keploy record -c "docker compose up" --container-name "redis-express" -n "keploy-network" +keploy record -c "docker compose up" --containerName "redis-express" -n "keploy-network" ``` The above command will start recording the API calls made to the application and will generate a test case in the `testcases/` directory. -> 💡 You can use Postman ,CURL or any other API testing tool to test the API calls. +> 💡 You can use Postman,CURL or any other API testing tool to test the API calls. ### Interact with Application Use Postman, CURL, or any other API testing tool to hit your API routes. This interaction will be recorded by Keploy. -Some curl commands to easily test the application are +Some curl commands to easily test the application are: 1. "http://localhost:3000/books" to retrieve the data of the books @@ -157,14 +171,12 @@ curl --location --request PUT 'http://localhost:3000/books/6' --header 'Content- }' ``` -Observe test run results: -Voila!! Our test cases have passed 🌟 - ### Test the Application using Keploy For server running locally. + ```bash -keploy test -c "npm run start" +sudo -E env PATH=$PATH keploy test -c "npm run start" --delay 10 ``` For the docker container. @@ -175,4 +187,4 @@ keploy test -c "docker compose up" --container-name "redis-express" -n "keploy-n Keploy will replay the recorded interactions and validate the responses against the expected results. -Voila! 🎉 You have successfully tested the application using Keploy. Keploy also generates coverage reports for the test-suites. +Voila!! Our test cases have passed 🌟 diff --git a/rest-express-mongo/README.md b/rest-express-mongo/README.md index dbaedf0..bb57474 100644 --- a/rest-express-mongo/README.md +++ b/rest-express-mongo/README.md @@ -4,23 +4,39 @@ The QuickWrites is a simple web application built with Express.js for managing n ## Features -- User authentication: Sign up, log in, and log out functionality with JWT tokens. +- User authentication and authorization using JWT tokens: Sign up, log in, and log out functionality. - Create, view, and delete notes: Users can create new notes, view their own notes, and delete notes they no longer need. -- Secure authentication: JWT tokens are used for user authentication and authorization. - Error handling: Proper error handling for authentication failures and other errors. ## Prerequisites -- Node.js installed on your machine -- MongoDB Atlas account or a local MongoDB database. +- Node.js >= 18.x +- MongoDB (local or Atlas) with a valid connection URI + +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. ## Start the server: -`npm start` +```bash +npm start +``` ## Running test cases in Keploy: -`keploy test -c "CMD_TO_RUN_APP" --delay 10` +```bash +sudo -E env PATH=$PATH keploy test -c "npm start" --delay 10 +``` ## Usage @@ -32,12 +48,25 @@ The QuickWrites is a simple web application built with Express.js for managing n ## Testing You can run the test suite to ensure the application functions correctly: -`npm test` +```bash +npm test +``` ### Postman Test Cases Here are the test cases written for Postman: -1. **Checks whether the response status code is 200, indicating a successful request**: pm.test("Response should have status 200", function () { pm.response.to.have.status(200); }); -2. . **Checks whether requesting with an unknown user should result in a response with a status code of 500, possibly indicating an internal server error.** pm.test("Unknown user should get a response 500", function () { pm.response.to.have.status(500); }); -3. **Checks whether providing a wrong password results in a response with a status code of 500.** pm.test("Wrong password should have status code 500", function () { pm.response.to.have.status(500); }); +1. Check whether the response status code is 200 +pm.test("Response should have status 200", function () { + pm.response.to.have.status(200); +}); + +2. Check whether requesting with an unknown user returns 500 +pm.test("Unknown user should get a response 500", function () { + pm.response.to.have.status(500); +}); + +3. Check whether providing a wrong password returns 500 +pm.test("Wrong password should have status code 500", function () { + pm.response.to.have.status(500); +}); diff --git a/ts-nhost/README.md b/ts-nhost/README.md index cfbe92c..13a1241 100644 --- a/ts-nhost/README.md +++ b/ts-nhost/README.md @@ -8,8 +8,11 @@ A sample App using Typescript and using nhost.io as Backend as a service ```bash git clone https://github.com/keploy/samples-typescript && cd samples-typescript/ts-nhost +``` # Install the dependencies + +```bash npm install ``` @@ -22,15 +25,28 @@ npm install 3. -> Go to Hasura Console and open Hasura 4. -> Get the x-hasura-admin-secret and GraphQL Endpoint and name them as HASURA_ADMIN_SECRET and GRAPHQL_ENDPOINT respectively in .env +#### Linux Users (Ubuntu/Debian) Note + +The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose. + +To avoid errors, install Docker Compose v2 using: + +```bash +sudo apt update +sudo apt install docker-compose-plugin +``` + +Then use `docker compose up` instead of `docker-compose up`. + ## Installing Keploy Let's get started by setting up the Keploy alias with this command: -```sh -curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh +```bash +curl --silent -O -L https://keploy.io/install.sh && source install.sh ``` -## Using Keploy : +## Using Keploy: There are 2 ways you can run this sample application. @@ -83,6 +99,7 @@ There are 2 ways you can run this sample application. ## Capture the test cases 1. **Start recording tests:** + ```bash sudo -E env "PATH=$PATH" keploy record -c 'ts-node src/app.ts' ``` @@ -92,6 +109,7 @@ There are 2 ways you can run this sample application. Make API Calls using Hoppscotch, Postman or cURL command. Keploy will capture those calls to generate test suites containing test cases and data mocks. 1. Create User + ```bash curl --request POST \ --url http://localhost:3000/users \ @@ -107,7 +125,8 @@ curl --request POST \ }' ``` -2. Get User +1. Get User + ```bash curl --request GET \ --url http://localhost:3000/users \ @@ -117,7 +136,8 @@ curl --request POST \ --header 'Host: localhost:3000' ``` -3. Delete user +1. Delete user + ```bash curl --request DELETE \ --url http://localhost:3000/users/ \ @@ -138,13 +158,9 @@ Before executing the test cases, please ensure to delete the newly created user ```bash sudo -E env "PATH=$PATH" keploy test -c 'ts-node src/app.ts' --delay 10 ``` - _Voila!! Our test cases have passed 🌟_ image - ---- - # Running the app using docker Since we have to setup our app using docker(make sure your docker is running) @@ -154,15 +170,15 @@ Since we have to setup our app using docker(make sure your docker is running) We will run the keploy in record mode with docker-compose to start our application:- ```bash -keploy record -c "sudo docker-compose up" --containerName "ts-nhost" - +sudo -E env PATH=$PATH keploy record -c "sudo docker-compose up" --containerName "ts-nhost" ``` -#### Let's generate the testcases. +#### Let's generate the testcases Make API Calls using Hoppscotch, Postman or cURL command. Keploy will capture those calls to generate test suites containing test cases and data mocks. 1. Create User + ```bash curl --request POST \ --url http://localhost:3000/users \ @@ -178,7 +194,8 @@ curl --request POST \ }' ``` -2. Get User +1. Get User + ```bash curl --request GET \ --url http://localhost:3000/users \ @@ -188,7 +205,8 @@ curl --request POST \ --header 'Host: localhost:3000' ``` -3. Delete user +1. Delete user + ```bash curl --request DELETE \ --url http://localhost:3000/users/ \ @@ -199,9 +217,11 @@ curl --request POST \ ``` ## Running the testcases + Let's run our captured test cases + ```bash keploy test -c 'sudo docker-compose up' --containerName "ts-nhost" --delay 10 ``` -_Voila!! Our testcases has passed 🌟_ +Voila!! Our test cases have passed 🌟_