robust_explain_non_path_payload-tests.json 3.67 KB
Newer Older
Siebers, Michael's avatar
Siebers, Michael committed
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
{
	"info": {
		"_postman_id": "1ef533c8-03ff-4cfc-a5fd-51a4664e1031",
		"name": "Robustness explain Non-Path Payload Copy",
		"description": "This collection tests whether the [Reasoning WebAPI for Dare2Del](https://gitlab.rz.uni-bamberg.de/cogsys/dare2del/demonstrator) (Version 1.0.0) handles POST requests to `explain` with semantically wrong payload gracefully. These should all result in 4xx responses. The response body should be an error response with the same code. The response message is not checked.\n\nThe collection is to be run with the data file  `robust_explain_non_path_payload-data.json`.",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "Querry Explanation",
			"event": [
				{
					"listen": "test",
					"script": {
						"exec": [
							"pm.test(pm.variables.get(\"test_prefix\") + \"Bad Request\", function () {",
							"    pm.expect(pm.response.code).to.eql(400);",
							"});",
							"",
							"pm.test(pm.variables.get(\"test_prefix\") + \"Valid error response body\", function() {",
							"    pm.response.to.be.withBody;",
							"    pm.response.to.be.json;",
							"",
							"    var Ajv = require('ajv');",
							"    ajv = new Ajv();",
							"    const validate = ajv.compile(JSON.parse(pm.variables.get(\"response-schema:error\")));",
							"",
							"    const jsonData = pm.response.json();",
							"    pm.expect(validate(jsonData)).to.be.true;",
							"    pm.expect(jsonData.code).to.eql(400);",
							"});"
						],
						"type": "text/javascript"
					}
				},
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							"if(! pm.collectionVariables.get(\"response-schema:error\")) {",
							"    var code_ok = false;",
							"    const schema_url = \"http://\" + pm.environment.get(\"SERVER\") + pm.environment.get(\"SCHEMA_PATH\") ",
							"            + \"/response-error-schema.json\";",
							"    pm.sendRequest(schema_url, function(err, response){",
							"        pm.test(\"Load error response schema: Status code is 200\", function () {",
							"            pm.expect(err).to.not.be.ok;",
							"            console.log(response);",
							"            pm.expect(response.code).to.eql(200);",
							"            code_ok = true;",
							"        });",
							"",
							"",
							"        pm.test(\"Load error response schema: Response is JSON object\", function() {",
							"            const jsonData = response.json();",
							"            pm.expect(jsonData).is.an(\"object\");",
							"",
							"            if(code_ok)",
							"                pm.collectionVariables.set(\"response-schema:error\", JSON.stringify(jsonData));",
							"        });",
							"    });",
							"}",
							"",
							"pm.variables.set(\"test_prefix\", pm.info.requestName + \"[\" +  (pm.info.iteration + 1).toString() + '/' ",
							"                                + pm.info.iterationCount.toString() + ']: ');"
						],
						"type": "text/javascript"
					}
				}
			],
			"protocolProfileBehavior": {
				"disabledSystemHeaders": {
					"connection": true
				}
			},
			"request": {
				"method": "POST",
				"header": [],
				"body": {
					"mode": "raw",
					"raw": "{{request_body}}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "http://{{SERVER}}/explain",
					"protocol": "http",
					"host": [
						"{{SERVER}}"
					],
					"path": [
						"explain"
					]
				}
			},
			"response": []
		}
	],
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		}
	]
121
}