Repository navigation
Expand file tree
/
Copy pathswapi (tests).json
More file actions
198 lines (198 loc) · 6.66 KB
/
Copy pathswapi (tests).json
File metadata and controls
198 lines (198 loc) · 6.66 KB
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
196
197
198
{
"info": {
"_postman_id": "a6ebfcb4-ad84-4ac6-be40-c8fae1c4e2a0",
"name": "swapi (tests)",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "27641822",
"_collection_link": "https://winter-comet-89484.postman.co/workspace/First~83ceb540-fd8b-46dc-b4cd-1258af9dbb83/collection/27641822-a6ebfcb4-ad84-4ac6-be40-c8fae1c4e2a0?action=share&creator=27641822&source=collection_link"
},
"item": [
{
"name": "Tests",
"event": [
{
"listen": "test",
"script": {
"exec": [
"//1.Проверка ответа в формате JSON\r",
"pm.test(\"Проверка ответа в формате JSON\", function(){\r",
" pm.response.to.have.jsonBody()\r",
"});\r",
"\r",
"//2. Проверка на наличие полей в ответе\r",
"pm.test(\"Проверка на наличие полей в ответе\", function(){\r",
" const jsonData = pm.response.json();\r",
"\r",
" pm.expect(jsonData).to.have.property(\"people\");\r",
" pm.expect(jsonData).to.have.property(\"planets\");\r",
" pm.expect(jsonData).to.have.property(\"films\");\r",
" pm.expect(jsonData).to.have.property(\"species\");\r",
" pm.expect(jsonData).to.have.property(\"vehicles\");\r",
" pm.expect(jsonData).to.have.property(\"starships\");\r",
" \r",
"}); \r",
"\r",
"//3. Знанение в ответе не NULL\r",
"\r",
"pm.test(\"Знанение в ответе не NULL\", function(){\r",
" var jsonData = pm.response.json();\r",
" pm.expect(jsonData.people).not.equal(null);\r",
" pm.expect(jsonData.planets).not.equal(null);\r",
" pm.expect(jsonData.films).not.equal(null);\r",
" pm.expect(jsonData.species).not.equal(null);\r",
" pm.expect(jsonData.vehicles).not.equal(null);\r",
" pm.expect(jsonData.starships).not.equal(null);\r",
"}); \r",
"\r",
"//4. Проверка наличия значений в ответе\r",
"pm.test(\"Проверка наличия значений в ответе\", function(){\r",
" var jsonData = pm.response.json();\r",
" pm.expect(jsonData.people).not.equal(\"\");\r",
" pm.expect(jsonData.planets).not.equal(\"\");\r",
" pm.expect(jsonData.films).not.equal(\"\");\r",
" pm.expect(jsonData.species).not.equal(\"\");\r",
" pm.expect(jsonData.vehicles).not.equal(\"\");\r",
" pm.expect(jsonData.starships).not.equal(\"\");\r",
"});\r",
"\r",
"//5. Проверка поля на необходимое значение\r",
"pm.test(\"Проверка поля на необходимое значение\", function(){\r",
" var jsonData = pm.response.json();\r",
" pm.expect(jsonData.people).to.equal(\"https://swapi.dev/api/people/\");\r",
" pm.expect(jsonData.planets).to.equal(\"https://swapi.dev/api/planets/\");\r",
" pm.expect(jsonData.films).to.equal(\"https://swapi.dev/api/films/\");\r",
" pm.expect(jsonData.species).to.equal(\"https://swapi.dev/api/species/\");\r",
" pm.expect(jsonData.vehicles).to.equal(\"https://swapi.dev/api/vehicles/\");\r",
" pm.expect(jsonData.starships).to.equal(\"https://swapi.dev/api/starships/\");\r",
"});\r",
"\r",
"//6. Проверка статуса 200\r",
"pm.test(\"Проверка статуса 200\", function () {\r",
" pm.response.to.have.status(200);\r",
"});\r",
"\r",
"//7. Статус сообщения OK\r",
"pm.test(\"Статус сообщения OK\", function(){\r",
" pm.response.to.have.status(\"OK\")\r",
"});\r",
"\r",
"//8. Время ответа менее 1000мс\r",
"pm.test(\"Время ответа менее 1000мс\", function () {\r",
" pm.expect(pm.response.responseTime).to.be.below(1000);\r",
"});\r",
"\r",
"//9. Content-Type is present\r",
"pm.test(\"Content-Type is present\", function () {\r",
" pm.response.to.have.header(\"Content-Type\");\r",
"});\r",
"\r",
"//10. Проверка Content-Type Json\r",
"pm.test(\"Проверка Content-Type Json\", function(){\r",
" pm.response.to.be.header(\"Content-Type\", \"application/json\")\r",
"});\r",
"\r",
"\r",
"\r",
""
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "https://swapi.dev/api/",
"protocol": "https",
"host": [
"swapi",
"dev"
],
"path": [
"api",
""
]
}
},
"response": []
},
{
"name": "Json schema",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var data = JSON.parse(responseBody);\r",
"\r",
"var schema = {\r",
" //тип ответа\r",
" \"type\": \"object\",\r",
" //обязательные свойства\r",
" \"required\": [\"people\",\"planets\",\"films\", \"species\",\"species\",\"starships\"],\r",
" //тип возвращаемых полей\r",
" \"properties\":{\r",
" \"people\": {\"type\":\"string\"},\r",
" \"planets\": {\"type\":\"string\"},\r",
" \"films\": {\"type\":\"string\"},\r",
" \"species\": {\"type\":\"string\"},\r",
" \"vehicles\": {\"type\":\"string\"},\r",
" \"starships\": {\"type\":\"string\"},\r",
"\r",
" }\r",
"};\r",
"\r",
"pm.test('Корректный ответ', function(){\r",
" pm.expect(tv4.validate(data, schema)).to.be.true;\r",
"});"
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "https://swapi.dev/api",
"protocol": "https",
"host": [
"swapi",
"dev"
],
"path": [
"api"
]
}
},
"response": []
}
]
}