Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cogsys
Dare2Del
Demonstrator - Reasoning WebAPI
Commits
23da7ad7
Commit
23da7ad7
authored
Jun 12, 2021
by
Siebers, Michael
Browse files
refined basic endpoint tests
adapted new schema filenames
parent
b8936776
Changes
6
Hide whitespace changes
Inline
Side-by-side
tests/api/endpoint_bg@add-tests.json
View file @
23da7ad7
...
...
@@ -6,48 +6,6 @@
"schema"
:
"https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item"
:
[
{
"name"
:
"Load Manipulation Response Schema"
,
"event"
:
[
{
"listen"
:
"test"
,
"script"
:
{
"exec"
:
[
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Status code is 200
\"
, function () {"
,
" pm.response.to.have.status(200);"
,
"});"
,
""
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Response is JSON object
\"
, function() {"
,
" pm.response.to.be.withBody;"
,
" pm.response.to.be.json;"
,
""
,
" const jsonData = pm.response.json();"
,
" pm.expect(jsonData).is.an(
\"
object
\"
);"
,
""
,
" pm.collectionVariables.set(
\"
expected_json_schema
\"
, JSON.stringify(jsonData));"
,
"});"
],
"type"
:
"text/javascript"
}
}
],
"request"
:
{
"method"
:
"GET"
,
"header"
:
[],
"url"
:
{
"raw"
:
"http://{{SERVER}}{{SCHEMA_PATH}}/type-manipulation-response-schema.json"
,
"protocol"
:
"http"
,
"host"
:
[
"{{SERVER}}{{SCHEMA_PATH}}"
],
"path"
:
[
"type-manipulation-response-schema.json"
]
}
},
"response"
:
[]
},
{
"name"
:
"Add Items"
,
"event"
:
[
...
...
@@ -61,15 +19,16 @@
""
,
"var jsonData;"
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
R
esponse
JSON schema valid
\"
, function() {"
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Valid r
esponse
body
\"
, function() {"
,
" pm.response.to.be.withBody;"
,
" pm.response.to.be.json;"
,
""
,
" const schema_text = pm.variables.get(
\"
expected_json_schema
\"
)"
,
" const schema = JSON.parse(schema_text)"
,
" var Ajv = require('ajv');"
,
" ajv = new Ajv();"
,
" const validate = ajv.compile(JSON.parse(pm.variables.get(
\"
response-schema:bg-add
\"
)));"
,
""
,
" jsonData = pm.response.json();"
,
" pm.expect(
tv4.
validate(jsonData
, schema
)).to.be.true;"
,
" pm.expect(validate(jsonData)).to.be.true;"
,
"});"
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Received and added all
\"
, function () {"
,
...
...
@@ -133,15 +92,16 @@
""
,
"var jsonData;"
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
R
esponse
JSON schema valid
\"
,
function() {"
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Valid r
esponse
body
\"
, function() {"
,
" pm.response.to.be.withBody;"
,
" pm.response.to.be.json;"
,
""
,
" const schema_text = pm.variables.get(
\"
expected_json_schema
\"
)"
,
" const schema = JSON.parse(schema_text)"
,
" var Ajv = require('ajv');"
,
" ajv = new Ajv();"
,
" const validate = ajv.compile(JSON.parse(pm.variables.get(
\"
response-schema:bg-add
\"
)));"
,
""
,
" jsonData = pm.response.json();"
,
" pm.expect(
tv4.
validate(jsonData
, schema
)).to.be.true;"
,
" pm.expect(validate(jsonData)).to.be.true;"
,
"});"
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Received all, added none
\"
, function () {"
,
...
...
@@ -199,6 +159,34 @@
"script"
:
{
"type"
:
"text/javascript"
,
"exec"
:
[
"utils = {"
,
"
\"
load_schema
\"
: function(source, target_variable, pm) {"
,
" if(! pm.collectionVariables.get(target_variable)) {"
,
" var code_ok = false;"
,
" const schema_url =
\"
http://
\"
+ pm.environment.get(
\"
SERVER
\"
) + pm.environment.get(
\"
SCHEMA_PATH
\"
) "
,
" +
\"
/
\"
+ source;"
,
" pm.sendRequest(schema_url, function(err, response){"
,
" pm.test(
\"
Load
\"
+ target_variable +
\"
: Status code is 200
\"
, function () {"
,
" pm.expect(err).to.not.be.ok;"
,
" pm.expect(response.code).to.eql(200);"
,
" code_ok = true;"
,
" });"
,
""
,
""
,
" pm.test(
\"
Load
\"
+ target_variable +
\"
: Response is JSON object
\"
, function() {"
,
" const jsonData = response.json();"
,
" pm.expect(jsonData).is.an(
\"
object
\"
);"
,
""
,
" if(code_ok)"
,
" pm.collectionVariables.set(target_variable, JSON.stringify(jsonData));"
,
" });"
,
" });"
,
" }"
,
" }"
,
"}"
,
""
,
"utils.load_schema(
\"
response-bg-add-schema.json
\"
,
\"
response-schema:bg-add
\"
, pm);"
,
""
,
"pm.variables.set(
\"
test_prefix
\"
,
\"
[
\"
+ (pm.info.iteration + 1).toString() + '/' "
,
" + pm.info.iterationCount.toString() + '] ' + pm.info.requestName +
\"
:
\"
);"
]
...
...
@@ -213,11 +201,5 @@
]
}
}
],
"variable"
:
[
{
"key"
:
"expected_json_schema"
,
"value"
:
""
}
]
}
\ No newline at end of file
tests/api/endpoint_bg@clear-tests.json
View file @
23da7ad7
...
...
@@ -7,7 +7,7 @@
},
"item"
:
[
{
"name"
:
"Load
Clear
Response Schema"
,
"name"
:
"Load
Manipulation
Response Schema"
,
"event"
:
[
{
"listen"
:
"test"
,
...
...
@@ -25,7 +25,7 @@
" const jsonData = pm.response.json();"
,
" pm.expect(jsonData).is.an(
\"
object
\"
);"
,
""
,
" pm.collectionVariables.set(
\"
expected_json_schema
\"
, JSON.stringify(jsonData));"
,
" pm.collectionVariables.set(
\"
response-schema:bg-clear
\"
, JSON.stringify(jsonData));"
,
"});"
],
"type"
:
"text/javascript"
...
...
@@ -55,21 +55,16 @@
"listen"
:
"test"
,
"script"
:
{
"exec"
:
[
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Case: Ok
\"
, function () {"
,
" pm.expect(pm.response.code).to.eql(200);"
,
"});"
,
""
,
"var jsonData;"
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Response JSON schema valid
\"
, function() {"
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Valid response body
\"
, function() {"
,
" pm.response.to.be.withBody;"
,
" pm.response.to.be.json;"
,
""
,
" const schema_text = pm.variables.get(
\"
expected_json_schema
\"
)"
,
" const schema = JSON.parse(schema_text)"
,
" var Ajv = require('ajv');"
,
" ajv = new Ajv();"
,
" const validate = ajv.compile(JSON.parse(pm.variables.get(
\"
response-schema:bg-clear
\"
)));"
,
""
,
" jsonData = pm.response.json();"
,
" pm.expect(
tv4.
validate(jsonData
, schema
)).to.be.true;"
,
" pm.expect(validate(jsonData)).to.be.true;"
,
"});"
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
All removed
\"
, function () {"
,
...
...
@@ -110,7 +105,7 @@
"response"
:
[]
},
{
"name"
:
"Remove No
l
Items"
,
"name"
:
"Remove No Items"
,
"event"
:
[
{
"listen"
:
"test"
,
...
...
@@ -122,15 +117,16 @@
""
,
"var jsonData;"
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
)
+
\"
R
esponse
JSON schema valid
\"
, function() {"
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Valid r
esponse
body
\"
, function() {"
,
" pm.response.to.be.withBody;"
,
" pm.response.to.be.json;"
,
""
,
" const schema_text = pm.variables.get(
\"
expected_json_schema
\"
)"
,
" const schema = JSON.parse(schema_text)"
,
" var Ajv = require('ajv');"
,
" ajv = new Ajv();"
,
" const validate = ajv.compile(JSON.parse(pm.variables.get(
\"
response-schema:bg-clear
\"
)));"
,
""
,
" jsonData = pm.response.json();"
,
" pm.expect(
tv4.
validate(jsonData
, schema
)).to.be.true;"
,
" pm.expect(validate(jsonData)).to.be.true;"
,
"});"
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
All removed
\"
, function () {"
,
...
...
@@ -190,11 +186,5 @@
]
}
}
],
"variable"
:
[
{
"key"
:
"expected_json_schema"
,
"value"
:
""
}
]
}
\ No newline at end of file
}
tests/api/endpoint_bg@remove-tests.json
View file @
23da7ad7
...
...
@@ -6,48 +6,6 @@
"schema"
:
"https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item"
:
[
{
"name"
:
"Load Manipulation Response Schema"
,
"event"
:
[
{
"listen"
:
"test"
,
"script"
:
{
"exec"
:
[
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Status code is 200
\"
, function () {"
,
" pm.response.to.have.status(200);"
,
"});"
,
""
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Response is JSON object
\"
, function() {"
,
" pm.response.to.be.withBody;"
,
" pm.response.to.be.json;"
,
""
,
" const jsonData = pm.response.json();"
,
" pm.expect(jsonData).is.an(
\"
object
\"
);"
,
""
,
" pm.collectionVariables.set(
\"
expected_json_schema
\"
, JSON.stringify(jsonData));"
,
"});"
],
"type"
:
"text/javascript"
}
}
],
"request"
:
{
"method"
:
"GET"
,
"header"
:
[],
"url"
:
{
"raw"
:
"http://{{SERVER}}{{SCHEMA_PATH}}/type-manipulation-response-schema.json"
,
"protocol"
:
"http"
,
"host"
:
[
"{{SERVER}}{{SCHEMA_PATH}}"
],
"path"
:
[
"type-manipulation-response-schema.json"
]
}
},
"response"
:
[]
},
{
"name"
:
"Remove Items"
,
"event"
:
[
...
...
@@ -61,15 +19,16 @@
""
,
"var jsonData;"
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
)
+
\"
R
esponse
JSON schema valid
\"
, function() {"
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Valid r
esponse
body
\"
, function() {"
,
" pm.response.to.be.withBody;"
,
" pm.response.to.be.json;"
,
""
,
" const schema_text = pm.variables.get(
\"
expected_json_schema
\"
)"
,
" const schema = JSON.parse(schema_text)"
,
" var Ajv = require('ajv');"
,
" ajv = new Ajv();"
,
" const validate = ajv.compile(JSON.parse(pm.variables.get(
\"
response-schema:bg-remove
\"
)));"
,
""
,
" jsonData = pm.response.json();"
,
" pm.expect(
tv4.
validate(jsonData
, schema
)).to.be.true;"
,
" pm.expect(validate(jsonData)).to.be.true;"
,
"});"
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Received and removed all
\"
, function () {"
,
...
...
@@ -133,15 +92,16 @@
""
,
"var jsonData;"
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
R
esponse
JSON schema valid
\"
, function() {"
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Valid r
esponse
body
\"
, function() {"
,
" pm.response.to.be.withBody;"
,
" pm.response.to.be.json;"
,
""
,
" const schema_text = pm.variables.get(
\"
expected_json_schema
\"
)"
,
" const schema = JSON.parse(schema_text)"
,
" var Ajv = require('ajv');"
,
" ajv = new Ajv();"
,
" const validate = ajv.compile(JSON.parse(pm.variables.get(
\"
response-schema:bg-remove
\"
)));"
,
""
,
" jsonData = pm.response.json();"
,
" pm.expect(
tv4.
validate(jsonData
, schema
)).to.be.true;"
,
" pm.expect(validate(jsonData)).to.be.true;"
,
"});"
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Received all, removed none
\"
, function () {"
,
...
...
@@ -199,8 +159,37 @@
"script"
:
{
"type"
:
"text/javascript"
,
"exec"
:
[
"utils = {"
,
"
\"
load_schema
\"
: function(source, target_variable, pm) {"
,
" if(! pm.collectionVariables.get(target_variable)) {"
,
" var code_ok = false;"
,
" const schema_url =
\"
http://
\"
+ pm.environment.get(
\"
SERVER
\"
) + pm.environment.get(
\"
SCHEMA_PATH
\"
) "
,
" +
\"
/
\"
+ source;"
,
" pm.sendRequest(schema_url, function(err, response){"
,
" pm.test(
\"
Load
\"
+ target_variable +
\"
: Status code is 200
\"
, function () {"
,
" pm.expect(err).to.not.be.ok;"
,
" pm.expect(response.code).to.eql(200);"
,
" code_ok = true;"
,
" });"
,
""
,
""
,
" pm.test(
\"
Load
\"
+ target_variable +
\"
: Response is JSON object
\"
, function() {"
,
" const jsonData = response.json();"
,
" pm.expect(jsonData).is.an(
\"
object
\"
);"
,
""
,
" if(code_ok)"
,
" pm.collectionVariables.set(target_variable, JSON.stringify(jsonData));"
,
" });"
,
" });"
,
" }"
,
" }"
,
"}"
,
""
,
"utils.load_schema(
\"
response-bg-remove-schema.json
\"
,
\"
response-schema:bg-remove
\"
, pm);"
,
""
,
"pm.variables.set(
\"
test_prefix
\"
,
\"
[
\"
+ (pm.info.iteration + 1).toString() + '/' "
,
" + pm.info.iterationCount.toString() + '] ' + pm.info.requestName +
\"
:
\"
);"
" + pm.info.iterationCount.toString() + '] ' + pm.info.requestName +
\"
:
\"
);"
,
""
]
}
},
...
...
@@ -213,11 +202,5 @@
]
}
}
],
"variable"
:
[
{
"key"
:
"expected_json_schema"
,
"value"
:
""
}
]
}
\ No newline at end of file
}
tests/api/endpoint_bg@show-tests.json
View file @
23da7ad7
...
...
@@ -6,6 +6,48 @@
"schema"
:
"https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item"
:
[
{
"name"
:
"Load Path Schema"
,
"event"
:
[
{
"listen"
:
"test"
,
"script"
:
{
"exec"
:
[
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Status code is 200
\"
, function () {"
,
" pm.response.to.have.status(200);"
,
"});"
,
""
,
""
,
"pm.test(pm.variables.get(
\"
test_prefix
\"
) +
\"
Response is JSON object
\"
, function() {"
,
" pm.response.to.be.withBody;"
,
" pm.response.to.be.json;"
,
""
,
" const jsonData = pm.response.json();"
,
" pm.expect(jsonData).is.an(
\"
object
\"
);"
,
""
,
" pm.collectionVariables.set(
\"
type-schema:path
\"
, JSON.stringify(jsonData));"
,
"});"
],
"type"
:
"text/javascript"
}
}
],
"request"
:
{
"method"
:
"GET"
,
"header"
:
[],
"url"
:
{
"raw"
:
"http://{{SERVER}}{{SCHEMA_PATH}}/type-path-schema.json"
,
"protocol"
:
"http"
,
"host"
:
[
"{{SERVER}}{{SCHEMA_PATH}}"
],
"path"
:
[
"type-path-schema.json"
]
}
},
"response"
:
[]
},
{
"name"
:
"Load File Schema"
,
"event"
:
[
...
...
@@ -25,7 +67,7 @@
" const jsonData = pm.response.json();"
,
" pm.expect(jsonData).is.an(
\"
object
\"
);"
,
""
,
" pm.collectionVariables.set(
\"
json_
schema:file
\"
, JSON.stringify(jsonData));"
,
" pm.collectionVariables.set(
\"
type-
schema:file
\"
, JSON.stringify(jsonData));"
,
"});"
],
"type"
:
"text/javascript"
...
...
@@ -67,7 +109,7 @@
" const jsonData = pm.response.json();"
,
" pm.expect(jsonData).is.an(
\"
object
\"
);"
,
""
,
" pm.collectionVariables.set(
\"
json_
schema:directory
\"
, JSON.stringify(jsonData));"
,
" pm.collectionVariables.set(
\"
type-
schema:directory
\"
, JSON.stringify(jsonData));"
,
"});"
],
"type"
:
"text/javascript"
...
...
@@ -109,7 +151,7 @@
" const jsonData = pm.response.json();"
,
" pm.expect(jsonData).is.an(
\"
object
\"
);"
,
""
,
" pm.collectionVariables.set(
\"
json_
schema:item
\"
, JSON.stringify(jsonData));"
,
" pm.collectionVariables.set(
\"
type-
schema:item
\"
, JSON.stringify(jsonData));"
,
"});"
],
"type"
:
"text/javascript"
...
...
@@ -151,7 +193,7 @@
" const jsonData = pm.response.json();"
,
" pm.expect(jsonData).is.an(
\"
object
\"
);"
,
""
,
" pm.collectionVariables.set(
\"
json_schema:response
\"
, JSON.stringify(jsonData));"
,
" pm.collectionVariables.set(
\"
response-schema:bg-show
\"
, JSON.stringify(jsonData));"
,
"});"
],
"type"
:
"text/javascript"
...
...
@@ -195,10 +237,11 @@
" ajv = new Ajv();"
,
""
,
" // prepare schemas"
,
" ajv.addSchema(JSON.parse(pm.variables.get(
\"
json_schema:item
\"
)));"
,
" ajv.addSchema(JSON.parse(pm.variables.get(
\"
json_schema:file
\"
)));"
,
" ajv.addSchema(JSON.parse(pm.variables.get(
\"
json_schema:directory
\"
))); "
,
" const schema = JSON.parse(pm.variables.get(
\"
json_schema:response
\"
));"
,
" ajv.addSchema(JSON.parse(pm.variables.get(
\"
type-schema:path
\"
)));"
,
" ajv.addSchema(JSON.parse(pm.variables.get(
\"
type-schema:item
\"
)));"
,
" ajv.addSchema(JSON.parse(pm.variables.get(
\"
type-schema:file
\"
)));"
,
" ajv.addSchema(JSON.parse(pm.variables.get(
\"
type-schema:directory
\"
))); "
,
" const schema = JSON.parse(pm.variables.get(
\"
response-schema:bg-show
\"
));"
,
""
,
" jsonData = pm.response.json();"
,
""
,
...
...
@@ -268,4 +311,4 @@
}
}
]
}
\ No newline at end of file
}
tests/api/endpoint_explain-tests.json
View file @
23da7ad7
...
...
@@ -27,7 +27,7 @@
""
,
" var Ajv = require('ajv');"
,
" ajv = new Ajv();"
,
" ajv.addSchema(JSON.parse(pm.variables.get(
\"
type-schema:
abs_
path
\"
)));"
,
" ajv.addSchema(JSON.parse(pm.variables.get(
\"
type-schema:path
\"
)));"
,
" const validate = ajv.compile(JSON.parse(pm.variables.get(
\"
response-schema:explain
\"
)));"
,
""
,
" jsonData = pm.response.json();"
,
...
...
@@ -62,7 +62,7 @@
"exec"
:
[
"utils.load_schema(
\"
response-explain-schema.json
\"
,
\"
response-schema:explain
\"
, pm);"
,
"utils.load_schema(
\"
response-error-schema.json
\"
,
\"
response-schema:error
\"
, pm);"
,
"utils.load_schema(
\"
type-
abs_
path-schema.json
\"
,
\"
type-schema:
abs_
path
\"
, pm);"
,
"utils.load_schema(
\"
type-path-schema.json
\"
,
\"
type-schema:path
\"
, pm);"
,
""
,
"pm.variables.set(
\"
test_prefix
\"
, pm.info.requestName +
\"
[
\"
+ (pm.info.iteration + 1).toString() + '/' "
,
" + pm.info.iterationCount.toString() + ']: ');"
,
...
...
@@ -147,31 +147,5 @@
]
}
}
],
"variable"
:
[
{
"key"
:
"path"
,
"value"
:
""
},
{
"key"
:
"expected_result"
,
"value"
:
""
},
{
"key"
:
"expected-schema"
,
"value"
:
""
},
{
"key"
:
"type-schema:abs_path"
,
"value"
:
""
},
{
"key"
:
"response-schema:error"
,
"value"
:
""
},
{
"key"
:
"response-schema:explain"
,
"value"
:
""
}
]
}
\ No newline at end of file
}
tests/api/endpoint_irrelevant@file-tests.json
View file @
23da7ad7
...
...
@@ -123,19 +123,5 @@
]
}
}
],
"variable"
:
[
{
"key"
:
"path"
,
"value"
:
""
},
{
"key"
:
"expected_result"
,
"value"
:
""
},
{
"key"
:
"expected-schema"
,
"value"
:
""
}
]
}
\ No newline at end of file
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment