Skip to content

Commit 8bad0ec

Browse files
committed
docs: update Linux Docker Compose note and fix README instructions
Signed-off-by: Sanika1356 <sanikasp135@gmail.com>
1 parent 0281b8c commit 8bad0ec

14 files changed

Lines changed: 572 additions & 272 deletions

File tree

bun-mongo/README.md

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
# Sample app with Bun.js and MongoDb
1+
# Sample app with Bun.js and MongoDB
22

3-
This is a sample app to test Keploy integration capabilities using [Bun.js](https://bun.sh) and MongoDb.
3+
This is a sample app to test Keploy integration capabilities using [Bun.js](https://bun.sh) and MongoDB.
44

5-
## Pre-requsite
6-
We first need to install bun.js.
7-
```zsh
5+
## Prerequisite
6+
7+
We first need to install bun.js.
8+
9+
```bash
810
# Bun.js is supported on macOS, Linux, and WSL
911
curl -fsSL https://bun.sh/install | bash
1012
```
13+
1114
## Setup app
1215

1316
Now that we have bun installed, we will setup our application
14-
```zsh
17+
18+
```bash
1519
git clone https://github.com/keploy/samples-typescript && cd samples-typescript/bun-mongo
1620

1721
# Install the dependencies
1822
bun install
1923
```
2024

21-
# Using Keploy :
25+
# Using Keploy
2226

23-
There are two ways to use Keploy:-
27+
There are two ways to use Keploy:-
2428

2529
1. [Natively on Linux/WSL](#natively-on-ubuntuwsl)
2630
2. [Using Docker](#running-sample-app-using-docker)
@@ -30,22 +34,24 @@ There are two ways to use Keploy:-
3034
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:-
3135

3236
#### Linux
37+
3338
1. AMD Architecture
34-
```zsh
39+
40+
```bash
3541
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp
3642

37-
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
43+
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy --version
3844
```
3945

40-
<details>
46+
<details>
4147
<Summary> 2. ARM Architecture </Summary>
4248

43-
44-
```zsh
49+
```bash
4550
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz" | tar xz -C /tmp
4651

47-
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
52+
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy --version
4853
```
54+
4955
</details>
5056

5157
#### Windows Subsystem for Linux (WSL)
@@ -55,16 +61,18 @@ On Windows, WSL is required to run Keploy Binary. You must be running Windows 10
5561
```bash
5662
wsl --install
5763
```
64+
5865
Once installed download and Install "Keploy Binary" :
5966

6067
```bash
6168
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp
6269

63-
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
70+
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy --version
6471
```
6572

6673
### Let's start the MongoDB Instance
67-
```zsh
74+
75+
```bash
6876
docker-compose up -d mongo
6977
```
7078

@@ -73,29 +81,32 @@ docker-compose up -d mongo
7381
### Capture the testcases
7482

7583
```bash
76-
sudo -E env PATH=$PATH Keploy record -c 'bun run supabun.ts'
84+
sudo -E env PATH=$PATH keploy record -c 'bun run supabun.ts'
7785
```
7886

79-
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.
87+
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.
8088

8189
1. Generate the testcases
90+
8291
```bash
8392
curl --request POST localhost:4200/save
8493
```
8594

8695
we will get the output:
8796

8897
```
89-
{"succes":true}
98+
{"success":true}
9099
```
91-
2. Fetch the data
92-
```bash
100+
101+
1. Fetch the data
102+
103+
```json
93104
curl --request GET localhost:4200/fetch
94105
```
95106

96107
this will provide us with the output:-
97108
```
98-
{"succes":{"_id":"6513cfec0bc1a17a36c06337","name":"Cow","sound":"Moo","__v":0}}
109+
{"success":{"_id":"6513cfec0bc1a17a36c06337","name":"Cow","sound":"Moo","__v":0}}
99110
```
100111
We will get the following output in our terminal
101112

@@ -108,57 +119,84 @@ We will get the following output in our terminal
108119
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).
109120

110121
## Create Network (if it doesn't already exist)
122+
111123
This creates a new docker network isolated from others (named keploy-network)
124+
112125
```bash
113126
docker network create keploy-network
114127
```
115128

116129
## Create Keploy Alias
130+
117131
Now, we need create an alias for Keploy:
132+
118133
```bash
119134
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'
120135
```
121136

122137
## Let's start the MongoDB Instance
138+
123139
```bash
124140
docker-compose up -d
125141
```
126142

143+
#### Linux Users (Ubuntu/Debian) Note
144+
145+
The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose.
146+
147+
To avoid errors, install Docker Compose v2 using:
148+
149+
```bash
150+
sudo apt update
151+
sudo apt install docker-compose-plugin
152+
```
153+
154+
Then use `docker compose up` instead of `docker-compose up`.
155+
127156
## Capture the testcases
157+
128158
1. We first need to build dockerimage of our application:-
159+
129160
```bash
130161
docker build -t bun-app:1.0 .
131162
```
132163

133-
2. Now we will run the keploy in record mode:-
164+
1. Now we will run the keploy in record mode:-
165+
134166
```bash
135-
keploy record -c "docker run -p 420:420 --name bunMongoApp --network keploy-network bun-app:1.0"
167+
keploy record -c "docker run -p 4200:4200 --name bunMongoApp --network keploy-network bun-app:1.0"
136168
```
137169

138170
### Let's generate the testcases.
139-
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.
171+
172+
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.
173+
140174
```bash
141-
curl --request POST localhost:420/save
175+
curl --request POST localhost:4200/save
142176
```
143177

144178
we will get the output:
145179

146180
```
147-
{"succes":true}
181+
{"success": true}
148182
```
183+
149184
2. Fetch the data
185+
150186
```bash
151-
curl --request GET localhost:420/fetch
187+
curl --request GET localhost:4200/fetch
152188
```
153189

154190
this will provide us with the output:-
191+
155192
```
156-
{"succes":{"_id":"6513cfec0bc1a17a36c06337","name":"Cow","sound":"Moo","__v":0}}
193+
{"success": {"_id":"6513cfec0bc1a17a36c06337","name":"Cow","sound":"Moo","__v":0}}
157194
```
195+
158196
We will get the following output in our terminal
159197

160198
![Testcase](./img/testcase-bun.png)
161199

162200
# Running the testcases
163201

164-
This is WIP and depended upon the issue by oven/bun & elysia:- https://github.com/elysiajs/elysia/issues/231
202+
This is a Work-in-Progress(WIP) and depends on this issue by oven/bun & elysia:- https://github.com/elysiajs/elysia/issues/231

crud-node-mongo/README.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Hotel Management Web App
2+
3+
This is a sample Hotel Management application used to demonstrate Keploy's capabilities for capturing and replaying API tests.
4+
25
1. **Node.js (version 14 or later):** Download and install it from [https://nodejs.org/en](https://nodejs.org/en).
36
2. **npm (version 5.6 or later):** This usually comes bundled with Node.js. Verify by running `npm -v` in your terminal.
7+
3. **Docker:** Required to run the MongoDB instance.
48

59
**1. Clone the Repository and Install Dependencies:**
610

@@ -12,12 +16,13 @@ npm install
1216
**2. Run the Development Server:**
1317
Run the following command to launch the development server:
1418

15-
```Bash
19+
```bash
1620
npm run dev
1721
```
22+
1823
# Different Jest Api Test cases
1924

20-
## Test Case 1: Book a Room
25+
## Test Case 1: View Bookings
2126

2227
```javascript
2328

@@ -35,15 +40,15 @@ test('View Bookings - Success', async () => {
3540
});
3641

3742
expect(response.status).toBe(200);
38-
expect(response.data.bookings.lenQgth).toBeGreaterThan(0); // Adjusted expectation
43+
expect(response.data.bookings.length).toBeGreaterThan(0); // Adjusted expectation
3944
});
4045

4146

4247
```
4348

4449
## Test Case 2: Edit a Booking
4550

46-
```bash
51+
```javascript
4752
test('Edit a Booking - Success', async () => {
4853
const requestBody = {
4954
userEmail: "new_email@example.com",
@@ -52,7 +57,7 @@ test('Edit a Booking - Success', async () => {
5257
endTime: "2024-04-23T11:00:00Z"
5358
};
5459

55-
const response = await axios.put('http://your-api-url/edit/<booking_id>', requestBody, {
60+
const response = await axios.put('http://localhost:3000/edit/{id}', requestBody, {
5661
headers: {
5762
'Content-Type': 'application/json'
5863
}
@@ -66,9 +71,9 @@ test('Edit a Booking - Success', async () => {
6671

6772
## Test Case 3: Cancel a Booking
6873

69-
```bash
74+
```javascript
7075
test('Cancel a Booking - Success', async () => {
71-
const response = await axios.delete('http://your-api-url/cancel/<booking_id>', {
76+
const response = await axios.delete('http://localhost:3000/cancel/{id}', {
7277
headers: {
7378
'Content-Type': 'application/json'
7479
}
@@ -77,14 +82,13 @@ test('Cancel a Booking - Success', async () => {
7782
expect(response.status).toBe(200);
7883
expect(response.data.message).toEqual("Booking cancelled successfully");
7984
});
80-
8185
```
82-
## Test Case 4: View Bookings
8386

87+
## Test Case 4: View Bookings
8488

85-
```bash
89+
```javascript
8690
test('View Bookings - Success', async () => {
87-
const response = await axios.get('http://your-api-url/view', {
91+
const response = await axios.get('http://localhost:3000/bookings/view', {
8892
headers: {
8993
'Content-Type': 'application/json'
9094
},
@@ -111,19 +115,34 @@ On Windows, WSL is required to run Keploy Binary.
111115
```bash
112116
wsl --install
113117
```
118+
114119
Once installed download and Install "Keploy Binary" :
115120

116121
```bash
117122
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp
118123

119-
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
124+
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy --version
120125
```
121126

122127
### Let's start the MongoDB Instance
123-
```zsh
128+
129+
```bash
124130
docker-compose up -d
125131
```
126132

133+
#### Linux Users (Ubuntu/Debian) Note
134+
135+
The default `docker.io` package may not include Docker Compose v2, which is required for running Keploy sample projects using Docker Compose.
136+
137+
To avoid errors, install Docker Compose v2 using:
138+
139+
```bash
140+
sudo apt update
141+
sudo apt install docker-compose-plugin
142+
```
143+
144+
Then use `docker compose up` instead of `docker-compose up`.
145+
127146
> **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`.**
128147
129148
### Capture the testcases
@@ -132,19 +151,17 @@ docker-compose up -d
132151
sudo -E env PATH=$PATH keploy record -c 'node src/app.js'
133152
```
134153

135-
136-
## we will get the output:
154+
## we will get the output
137155

138156
![Testcase](./img/p1.jpg)
139157

140158
## Running the testcases
141159

142-
143160
```bash
144-
keploy test -c "CMD_TO_RUN_APP" --delay 10
145-
161+
sudo -E env PATH=$PATH keploy test -c 'node src/app.js' --delay 10
146162

147163
```
164+
148165
![Testcase](./img/p2.jpg)
149166

150167
![Testcase](./img/p3.jpg)

0 commit comments

Comments
 (0)