-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHabr.postman_collection.json
195 lines (195 loc) · 4.8 KB
/
Habr.postman_collection.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
{
"info": {
"_postman_id": "8714797e-0f58-4fef-a6aa-77d4ba63a49c",
"name": "Habr",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "24101607"
},
"item": [
{
"name": "Get user id",
"event": [
{
"listen": "test",
"script": {
"exec": [
"try {",
" // сохраняем userId из json ответа в переменную окружения",
" pm.environment.set(\"userId\", pm.response.json().args.userId);",
"} catch(e) {",
" // выводим исключение в консоль",
" console.log(e);",
"}"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://postman-echo.com/get?userId=777",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"get"
],
"query": [
{
"key": "userId",
"value": "777"
}
]
}
},
"response": []
},
{
"name": "Update username",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// проверим, что userId из окружения равен userId из ответа",
"pm.test(\"userId from env is equal to userId from response\", function () {",
" pm.expect(parseInt(pm.environment.get(\"userId\"))).to.equal(",
" pm.response.json().data.userId",
" );",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\"userId\": {{userId}}, \"username\": \"Bob\"}\n",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://postman-echo.com/post",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"post"
]
}
},
"response": []
},
{
"name": "Check json",
"event": [
{
"listen": "test",
"script": {
"exec": [
"// получаем профиль из ответа",
"var profile = pm.response.json().data.profile;",
"",
"// описываем схему модели",
"var scheme = {",
" // указываем тип объекта",
" \"type\": \"object\",",
" // указываем обязательные свойства",
" \"required\": [\"userId\", \"username\"],",
" // описываем свойства",
" \"properties\": {",
" \"userId\": {\"type\": \"integer\"},",
" \"username\": {\"type\": \"string\"},",
" \"age\": {\"type\": \"integer\"},",
" // описываем массив",
" \"scores\": {",
" \"type\": \"array\",",
" // тип элементов",
" \"items\": {\"type\": \"integer\"}",
" },",
" // описываем вложенный объект",
" \"rating\": {",
" \"type\": \"object\",",
" \"properties\": {",
" \"min\": {\"type\": \"integer\"},",
" \"max\": {\"type\": \"integer\"}",
" }",
" }",
" }",
"};",
"",
"pm.test('Schema is valid', function() {",
" // валидируем объект profile с помощью правил из scheme",
" var isValidScheme = tv4.validate(profile, scheme, true, true);",
"",
" // ожидаем, что результат валидации true",
" pm.expect(isValidScheme).to.be.true;",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"profile\" : {\n \"userId\": {{userId}},\n \"username\": \"Bob\",\n \"scores\": [1, 2, 3, 4, 5],\n \"age\": 21,\n \"rating\": {\"min\": 20, \"max\": 100}\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://postman-echo.com/post",
"protocol": "https",
"host": [
"postman-echo",
"com"
],
"path": [
"post"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"pm.test(\"Status is ok, response is json\", function () {",
" pm.response.to.be.ok;",
" pm.response.to.be.json;",
"});"
]
}
}
]
}