-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnewsapi.org.postman_collection.json
185 lines (185 loc) · 5.73 KB
/
newsapi.org.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
{
"info": {
"_postman_id": "99efc625-a56e-40a9-9285-c63b7176aa11",
"name": "newsapi.org",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Latest News",
"event": [
{
"listen": "test",
"script": {
"id": "d485fed6-226c-45df-9ff5-9d003bd8d1c6",
"exec": [
"eval(environment.commonTests)().testType.positive();",
"//Below is checking that the data has the correct schema. If we wanted to check correct data we could just add .and.is(data);",
"var jsonData = JSON.parse(responseBody);",
"var schema = {",
" \"properties\": {",
" \"status\": {",
" \"type\": \"string\"",
" },",
" \"totalResults\": {",
" \"type\": \"number\"",
" },",
" \"articles\": {",
" \"type\": \"array\",",
" \"properties\": {",
" \"source\": {",
" \"id\": {",
"",
" },",
" \"name\": {",
" \"type\": \"string\"",
" }",
" },",
" \"author\": {",
" \"type\": \"string\"",
" },",
" \"title\": {",
" \"type\": \"string\"",
" },",
" \"description\": {",
" \"type\": \"string\"",
" },",
" \"url\": {",
" \"type\": \"string\"",
" },",
" \"urlToImage\": {",
" \"type\": \"string\"",
" },",
" \"publishedAt\": {",
" \"type\": \"string\"",
" //\"format\": /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$/",
" },",
" \"content\": {",
" \"type\": \"string\"",
" }",
" }",
" }",
" }",
"};",
"tests[\"Schema is valid\"] = tv4.validate(JSON.parse(responseBody), schema);"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"id": "8180a0cc-eae4-4559-958a-45055c90ccea",
"exec": [
"//Here we create a function that is then stored in the environmental variable. This is so we can then call this from any following test.",
"//This must be in the first test of the collection or collection folder.",
"postman.setEnvironmentVariable(\"commonTests\", () => {",
" //These are test that are ran on every call of the commonTest.",
" pm.test(\"Response time is less than 200ms\", function () {",
" pm.expect(pm.response.responseTime).to.be.below(200);",
" });",
" pm.test(\"Response must be valid and have a body\", function() {",
" pm.response.to.be.json; // this assertion checks if a body exists",
" });",
" ",
" //We then create a function within commonTest for the Successful test we will run.",
" var positive = () => {",
" ",
" pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
" });",
" pm.test(\"Response does not error\", function() {",
" pm.response.to.not.be.error;",
" pm.response.to.not.have.jsonBody(\"error\");",
" });",
" ",
" }",
" //This is a function for the negative test, or the test we want to fail.",
" var negative = () => {",
" pm.test(\"Status code is 400\", function () {",
" pm.response.to.have.status(400);",
" });",
" }",
" //Lastly we return the functions, so we can call them from outside the environmental variable",
" return {",
" testType: {",
" positive,",
" negative",
" }",
" };",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "X-Api-Key",
"value": "{{apiKey}}",
"type": "text"
}
],
"url": {
"raw": "{{url}}/top-headlines?country=us",
"host": [
"{{url}}"
],
"path": [
"top-headlines"
],
"query": [
{
"key": "country",
"value": "us"
}
]
}
},
"response": []
},
{
"name": "Latest News error",
"event": [
{
"listen": "test",
"script": {
"id": "947d0244-c49a-438b-87ab-86503f122e0e",
"exec": [
"eval(environment.commonTests)().testType.negative();",
"const jsonData = pm.response.json();",
"pm.test(\"Has correct schema\", function() {",
" pm.expect(jsonData.status).to.be.a(\"string\").equals(\"error\", \"Status is not a string or not error\");",
" pm.expect(jsonData.code).to.be.a(\"string\", \"code is not a string\");",
" pm.expect(jsonData.message).to.be.a(\"string\", \"message is not a string\");",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [
{
"key": "X-Api-Key",
"value": "{{apiKey}}",
"type": "text"
}
],
"url": {
"raw": "{{url}}/top-headlines",
"host": [
"{{url}}"
],
"path": [
"top-headlines"
]
}
},
"response": []
}
]
}