-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch-complex.feature
37 lines (32 loc) · 987 Bytes
/
search-complex.feature
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
@ignore
Feature:
Scenario:
# pre-process call argument
* def search = __arg
* remove search.missing
* url demoBaseUrl
Given path 'search'
And params search
When method get
Then status 200
# '#[1]' means validate if an array, and length is 1
* def exists = function(v){ return v ? '#[1]' : null }
# besides the built-in variable '__arg', each key within it is available by name
# note how the '##' marker is used to auto-remove BEFORE the match
# there are simpler ways to do this, but just for demo
* def expected = { name: '##(exists(name))', country: '##(exists(country))', active: '##(exists(active))', limit: '##(exists(limit))' }
* match response == expected
# demo of how to turn an array of strings into json keys
* def fun =
"""
function(arr) {
var res = {};
for (var i = 0; i < arr.length; i++) {
var key = arr[i];
res[key] = '#notnull';
}
return res;
}
"""
# response should NOT contain a key expected to be missing
* match response !contains fun(missing)