-
Notifications
You must be signed in to change notification settings - Fork 2
/
newsapi.org.postman_environment.json
24 lines (24 loc) · 3.68 KB
/
newsapi.org.postman_environment.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
{
"id": "cd7a51a9-a52b-4047-8f4f-59c5c63e7937",
"name": "newsapi.org",
"values": [
{
"key": "url",
"value": "https://newsapi.org/v2",
"enabled": true
},
{
"key": "apiKey",
"value": "810d6a9b7292490c83796e669a0341aa",
"enabled": true
},
{
"key": "commonTests",
"value": "() => {\n //These are test that are ran on every call of the commonTest.\n tests[\"Response time is less than 500ms\"] = responseTime < 500;\n tests['JSON array is not empty'] = (responseBody.length > 0);\n //We then create a function within commonTest for the Successful test we will run.\n var positive = () => {\n tests[\"Status code is 200\"] = responseCode.code === 200;\n //Below is checking that the data has the correct schema. If we wanted to check correct data we could just add .and.is(data);\n var jsonData = JSON.parse(responseBody);\n var schema = {\n \"properties\": {\n \"status\": {\n \"type\": \"string\"\n },\n \"totalResults\": {\n \"type\": \"number\"\n },\n \"articles\": {\n \"type\": \"array\",\n \"properties\": {\n \"source\": {\n \"id\": {\n\n },\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"author\": {\n \"type\": \"string\"\n },\n \"title\": {\n \"type\": \"string\"\n },\n \"description\": {\n \"type\": \"string\"\n },\n \"url\": {\n \"type\": \"string\"\n },\n \"urlToImage\": {\n \"type\": \"string\"\n },\n \"publishedAt\": {\n \"type\": \"string\"\n //\"format\": /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$/\n },\n \"content\": {\n \"type\": \"string\"\n }\n }\n }\n }\n };\n pm.test('Schema is valid', function() {\n tests[\"Schema is valid\"] = tv4.validate(JSON.parse(responseBody), schema);\n });\n }\n //This is a function for the negative test, or the test we want to fail.\n var negative = () => {\n tests[\"Status code is 400\"] = responseCode.code === 400;\n const jsonData = pm.response.json();\n pm.test(\"Has correct schema\", function() {\n pm.expect(jsonData.status).to.be.a(\"string\").equals(\"error\");\n pm.expect(jsonData.code).to.be.a(\"string\");\n pm.expect(jsonData.message).to.be.a(\"string\");\n });\n }\n //Lastly we return the functions, so we can call them from outside the environmental variable\n return {\n testType: {\n positive,\n negative\n }\n };\n}",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2019-07-06T17:34:39.322Z",
"_postman_exported_using": "Postman/7.1.1"
}