-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallback_test.go
77 lines (70 loc) · 2.12 KB
/
callback_test.go
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
package openapi_test
import (
"testing"
"github.com/MarkRosemaker/openapi"
)
var invalidCallback = &openapi.Callback{
"{$request.query.callbackUrl}/data": {
Value: &openapi.PathItem{
Parameters: openapi.ParameterList{{
Value: &openapi.Parameter{},
}},
},
},
}
func TestCallback_JSON(t *testing.T) {
t.Parallel()
// The following example uses the user provided `queryUrl` query string parameter to define the callback URL.
// This is an example of how to use a callback object to describe a WebHook callback that goes with the subscription operation to enable registering for the WebHook.
testJSON(t, []byte(`{
"{$request.query.queryUrl}": {
"post": {
"requestBody": {
"description": "Callback payload",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SomePayload"
}
}
}
},
"responses": {
"200": {
"description": "callback successfully processed"
}
}
}
}
}
`), &openapi.Callback{})
// The following example shows a callback where the server is hard-coded, but the query string parameters are populated from the `id` and `email` property in the request body.
testJSON(t, []byte(`{
"http://notificationServer.com?transactionId={$request.body#/id}&email={$request.body#/email}": {
"post": {
"requestBody": {
"description": "Callback payload",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SomePayload"
}
}
}
},
"responses": {
"200": {
"description": "callback successfully processed"
}
}
}
}
}`), &openapi.Callback{})
}
func TestCallback_Validate_Error(t *testing.T) {
if err := invalidCallback.Validate(); err == nil {
t.Fatal("expected error")
} else if want := `["{$request.query.callbackUrl}/data"].parameters[0].name is required`; want != err.Error() {
t.Fatalf("expected %q, got %q", want, err.Error())
}
}