Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 68 additions & 30 deletions bun-mongo/README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
```

<details>
<details>
<Summary> 2. ARM Architecture </Summary>


```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
```

</details>

#### Windows Subsystem for Linux (WSL)
Expand All @@ -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
```

Expand All @@ -73,29 +81,32 @@ 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
```

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

Expand All @@ -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
53 changes: 35 additions & 18 deletions crud-node-mongo/README.md
Original file line number Diff line number Diff line change
@@ -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:**

Expand All @@ -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

Expand All @@ -35,15 +40,15 @@ 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
});


```

## Test Case 2: Edit a Booking

```bash
```javascript
test('Edit a Booking - Success', async () => {
const requestBody = {
userEmail: "[email protected]",
Expand All @@ -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/<booking_id>', requestBody, {
const response = await axios.put('http://localhost:3000/edit/{id}', requestBody, {
headers: {
'Content-Type': 'application/json'
}
Expand All @@ -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/<booking_id>', {
const response = await axios.delete('http://localhost:3000/cancel/{id}', {
headers: {
'Content-Type': 'application/json'
}
Expand All @@ -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'
},
Expand All @@ -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
Expand All @@ -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)
Loading