Skip to content

Commit 7e02125

Browse files
API Testing Collection Document added
0 parents commit 7e02125

File tree

1 file changed

+194
-0
lines changed

1 file changed

+194
-0
lines changed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
{
2+
"info": {
3+
"_postman_id": "b075cfee-0a90-4dea-9fea-d96b5fd31749",
4+
"name": "Postman API Testing",
5+
"description": "### _Learning advanced features of Postman, emphasizing its capabilities beyond basic requests, and encourages viewers to explore its full potential._",
6+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
7+
"_exporter_id": "33792038"
8+
},
9+
"item": [
10+
{
11+
"name": "Auth",
12+
"item": [
13+
{
14+
"name": "Register User Random",
15+
"event": [
16+
{
17+
"listen": "prerequest",
18+
"script": {
19+
"exec": [
20+
"function getRandomRoles(){\r",
21+
" const roles = [\"ADMIN\", \"USER\"]\r",
22+
" return roles[Math.floor(Math.random() * roles.length)]\r",
23+
"}\r",
24+
"\r",
25+
"function getRandomUsername(){\r",
26+
" const letters = \"abcdefghijklmopqrstuvwxyz\"\r",
27+
" let username = \"\"\r",
28+
" for (let i = 0; i < 8; i++){\r",
29+
" username += letters.charAt(Math.floor(Math.random() * letters.length))\r",
30+
" }\r",
31+
"\r",
32+
" return username\r",
33+
"}\r",
34+
"\r",
35+
"pm.environment.set(\"randomRole\", getRandomRoles())\r",
36+
"pm.environment.set(\"randomUsername\", getRandomUsername())"
37+
],
38+
"type": "text/javascript",
39+
"packages": {}
40+
}
41+
},
42+
{
43+
"listen": "test",
44+
"script": {
45+
"exec": [
46+
"pm.test(\"Response status code is 201\", function () {",
47+
" pm.expect(pm.response.code).to.equal(201);",
48+
"});",
49+
"",
50+
"",
51+
"pm.test(\"Data object is present in the response\", function () {",
52+
" const responseData = pm.response.json();",
53+
" ",
54+
" pm.expect(responseData.data).to.exist;",
55+
"});",
56+
"",
57+
"",
58+
"pm.test(\"User object is present within the data object\", function () {",
59+
" const responseData = pm.response.json();",
60+
" ",
61+
" pm.expect(responseData).to.have.property('data');",
62+
" pm.expect(responseData.data).to.have.property('user');",
63+
"});",
64+
"",
65+
"",
66+
"pm.test(\"Email and username are non-empty strings\", function () {",
67+
" const responseData = pm.response.json();",
68+
" ",
69+
" pm.expect(responseData).to.be.an('object');",
70+
" pm.expect(responseData.data.user.email).to.be.a('string').and.to.have.lengthOf.at.least(1, \"Email should not be empty\");",
71+
" pm.expect(responseData.data.user.username).to.be.a('string').and.to.have.lengthOf.at.least(1, \"Username should not be empty\");",
72+
"});",
73+
"",
74+
"",
75+
"pm.test(\"Avatar object contains url, localPath, and _id fields within the user object\", function () {",
76+
" const responseData = pm.response.json();",
77+
" ",
78+
" pm.expect(responseData).to.be.an('object');",
79+
" pm.expect(responseData.data.user.avatar).to.be.an('object');",
80+
" pm.expect(responseData.data.user.avatar.url).to.be.a('string');",
81+
" pm.expect(responseData.data.user.avatar.localPath).to.be.a('string');",
82+
" pm.expect(responseData.data.user.avatar._id).to.be.a('string');",
83+
"});"
84+
],
85+
"type": "text/javascript"
86+
}
87+
}
88+
],
89+
"request": {
90+
"method": "POST",
91+
"header": [],
92+
"body": {
93+
"mode": "raw",
94+
"raw": "{\r\n \"email\": \"{{$randomEmail}}\",\r\n \"password\": \"test@123\",\r\n \"role\": \"{{randomRole}}\",\r\n \"username\": \"{{randomUsername}}\"\r\n}",
95+
"options": {
96+
"raw": {
97+
"language": "json"
98+
}
99+
}
100+
},
101+
"url": {
102+
"raw": "{{freeapi}}/users/register",
103+
"host": [
104+
"{{freeapi}}"
105+
],
106+
"path": [
107+
"users",
108+
"register"
109+
]
110+
},
111+
"description": "### Register User\n\nThis endpoint allows you to register a new user.\n\n#### Request Body\n\n- email (text, required): The email of the user.\n \n- password (text, required): The password for the user account.\n \n- role (text, required): The role of the user.\n \n- username (text, required): The username of the user.\n \n\n#### Response\n\nThe response will be a JSON object with the following schema:\n\n``` json\n{\n \"type\": \"object\",\n \"properties\": {\n \"statusCode\": {\n \"type\": \"number\"\n },\n \"data\": {\n \"type\": \"object\",\n \"properties\": {\n \"user\": {\n \"type\": \"object\",\n \"properties\": {\n \"_id\": {\n \"type\": \"string\"\n },\n \"avatar\": {\n \"type\": \"object\",\n \"properties\": {\n \"url\": {\n \"type\": \"string\"\n },\n \"localPath\": {\n \"type\": \"string\"\n },\n \"_id\": {\n \"type\": \"string\"\n }\n }\n },\n \"username\": {\n \"type\": \"string\"\n },\n \"email\": {\n \"type\": \"string\"\n },\n \"role\": {\n \"type\": \"string\"\n },\n \"loginType\": {\n \"type\": \"string\"\n },\n \"isEmailVerified\": {\n \"type\": \"boolean\"\n },\n \"createdAt\": {\n \"type\": \"string\"\n },\n \"updatedAt\": {\n \"type\": \"string\"\n },\n \"__v\": {\n \"type\": \"number\"\n }\n }\n },\n \"message\": {\n \"type\": \"string\"\n },\n \"success\": {\n \"type\": \"boolean\"\n }\n }\n }\n }\n}\n\n ```"
112+
},
113+
"response": []
114+
}
115+
]
116+
},
117+
{
118+
"name": "Public",
119+
"item": [
120+
{
121+
"name": "Get Random Joke",
122+
"event": [
123+
{
124+
"listen": "test",
125+
"script": {
126+
"exec": [
127+
"pm.test(\"Response status code is 200\", function () {",
128+
" pm.expect(pm.response.to.have.status(200));",
129+
"});",
130+
"",
131+
"",
132+
"pm.test(\"Data object is present in the response\", function () {",
133+
" const responseData = pm.response.json();",
134+
" ",
135+
" pm.expect(responseData.data).to.exist;",
136+
"});",
137+
"",
138+
"",
139+
"pm.test(\"Categories array should be empty\", function () {",
140+
" const responseData = pm.response.json();",
141+
" ",
142+
" pm.expect(responseData).to.be.an('object');",
143+
" pm.expect(responseData.data.categories).to.be.an('array').that.is.empty;",
144+
"});",
145+
"",
146+
"",
147+
"pm.test(\"Id is a non-negative number\", function () {",
148+
" const responseData = pm.response.json();",
149+
" ",
150+
" pm.expect(responseData).to.be.an('object');",
151+
" pm.expect(responseData.data.id).to.be.a('number').and.to.satisfy(id => id >= 0, \"Id should be a non-negative number\");",
152+
"});",
153+
"",
154+
"",
155+
"pm.test(\"Content is a non-empty string\", function () {",
156+
" const responseData = pm.response.json();",
157+
"",
158+
" pm.expect(responseData).to.be.an('object');",
159+
" pm.expect(responseData.data.content).to.be.a('string').and.to.have.lengthOf.at.least(1, \"Content should not be empty\");",
160+
"});"
161+
],
162+
"type": "text/javascript"
163+
}
164+
}
165+
],
166+
"request": {
167+
"method": "GET",
168+
"header": [],
169+
"url": {
170+
"raw": "{{freeapi}}/public/randomjokes/joke/random",
171+
"host": [
172+
"{{freeapi}}"
173+
],
174+
"path": [
175+
"public",
176+
"randomjokes",
177+
"joke",
178+
"random"
179+
]
180+
},
181+
"description": "### GET /public/randomjokes/joke/random\n\nThis endpoint retrieves a random joke from the public collection.\n\n#### Request Body\n\nThis endpoint does not require a request body.\n\n#### Response\n\n- Status: 200\n \n- Content-Type: application/json\n \n\n``` json\n{\n \"statusCode\": 0,\n \"data\": {\n \"categories\": [],\n \"id\": 0,\n \"content\": \"\"\n },\n \"message\": \"\",\n \"success\": true\n}\n\n ```\n\nThe response contains the following fields:\n\n- `statusCode` (number): The status code of the response.\n \n- `data` (object): An object containing the joke details.\n \n - `categories` (array): An array of categories associated with the joke.\n \n - `id` (number): The ID of the joke.\n \n - `content` (string): The content of the joke.\n \n- `message` (string): Any additional message from the server.\n \n- `success` (boolean): Indicates if the request was successful."
182+
},
183+
"response": []
184+
}
185+
]
186+
}
187+
],
188+
"variable": [
189+
{
190+
"key": "freeapi",
191+
"value": "https://api.freeapi.app/api/v1"
192+
}
193+
]
194+
}

0 commit comments

Comments
 (0)