-
Notifications
You must be signed in to change notification settings - Fork 11
/
bodySchema.feature
108 lines (105 loc) · 2.48 KB
/
bodySchema.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
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
@javascript
Feature: Body validation using JSON Schema (draft v4)
Background:
Given I expect "body" to match the following "JSON Schema":
"""
{
"type": "object",
"$schema": "https://json-schema.org/draft-04/schema",
"required": ["version", "user"],
"properties": {
"version": {
"type": "string"
},
"permissions": {
"type": "object",
"required": ["read", "write"],
"properties": {
"read": {
"type": "boolean"
},
"write": {
"type": "boolean"
}
}
},
"user": {
"type": "object",
"required": ["id"],
"properties": {
"id": {
"type": "number"
}
}
}
}
}
"""
Scenario: With body matching the schema
Given the actual "body" equals:
"""
{
"version": "stable",
"user": {
"id": 1
},
"permissions": {
"read": true,
"write": true
}
}
"""
When Gavel validates the HTTP message
Then the actual HTTP message is valid
And the result field "body" equals:
"""
{
"valid": true,
"kind": "json",
"values": {
"actual": "{\n \"version\": \"stable\",\n \"user\": {\n \"id\": 1\n },\n \"permissions\": {\n \"read\": true,\n \"write\": true\n }\n}"
},
"errors": []
}
"""
Scenario: With missing required properties
Given the actual "body" equals:
"""
{
"permissions": {
"read": true,
"write": false
},
"user": {
"firstName": "John"
}
}
"""
When Gavel validates the HTTP message
Then the actual HTTP message is NOT valid
And the result field "body" equals:
"""
{
"valid": false,
"kind": "json",
"values": {
"actual": "{\n \"permissions\": {\n \"read\": true,\n \"write\": false\n },\n \"user\": {\n \"firstName\": \"John\"\n }\n}"
},
"errors": [
{
"message": "At '/version' Missing required property: version",
"location": {
"pointer": "/version",
"property": ["version"]
}
},
{
"message": "At '/user/id' Missing required property: id",
"location": {
"pointer": "/user/id",
"property": ["user", "id"]
}
}
]
}
"""