forked from mendixlabs/mxcli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_microflows_format_restcall_test.go
More file actions
110 lines (100 loc) · 3.51 KB
/
cmd_microflows_format_restcall_test.go
File metadata and controls
110 lines (100 loc) · 3.51 KB
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
// SPDX-License-Identifier: Apache-2.0
package executor
import (
"testing"
"github.com/mendixlabs/mxcli/sdk/microflows"
)
// =============================================================================
// formatRestCallAction
// =============================================================================
func TestFormatRestCallAction_GET(t *testing.T) {
e := newTestExecutor()
action := µflows.RestCallAction{
HttpConfiguration: µflows.HttpConfiguration{
HttpMethod: microflows.HttpMethodGet,
LocationTemplate: "https://api.example.com/orders",
},
ResultHandling: µflows.ResultHandlingString{VariableName: "Response"},
}
got := e.formatRestCallAction(action)
if got == "" {
t.Fatal("expected non-empty output")
}
assertContains(t, got, "rest call get")
assertContains(t, got, "'https://api.example.com/orders'")
assertContains(t, got, "$Response = ")
assertContains(t, got, "returns String")
}
func TestFormatRestCallAction_HttpResponse(t *testing.T) {
e := newTestExecutor()
action := µflows.RestCallAction{
HttpConfiguration: µflows.HttpConfiguration{
HttpMethod: microflows.HttpMethodGet,
LocationTemplate: "https://api.example.com/orders",
},
ResultHandling: µflows.ResultHandlingHttpResponse{VariableName: "Response"},
}
got := e.formatRestCallAction(action)
assertContains(t, got, "$Response = ")
assertContains(t, got, "returns response")
}
func TestFormatRestCallAction_POST_CustomBody(t *testing.T) {
e := newTestExecutor()
action := µflows.RestCallAction{
HttpConfiguration: µflows.HttpConfiguration{
HttpMethod: microflows.HttpMethodPost,
LocationTemplate: "https://api.example.com/orders",
},
RequestHandling: µflows.CustomRequestHandling{
Template: `{"name": "test"}`,
},
ResultHandling: µflows.ResultHandlingNone{},
}
got := e.formatRestCallAction(action)
assertContains(t, got, "rest call post")
assertContains(t, got, "body '{\"name\": \"test\"}'")
assertContains(t, got, "returns Nothing")
}
func TestFormatRestCallAction_WithHeaders(t *testing.T) {
e := newTestExecutor()
action := µflows.RestCallAction{
HttpConfiguration: µflows.HttpConfiguration{
HttpMethod: microflows.HttpMethodGet,
LocationTemplate: "https://api.example.com",
CustomHeaders: []*microflows.HttpHeader{
{Name: "Authorization", Value: "'Bearer ' + $Token"},
},
},
ResultHandling: µflows.ResultHandlingString{VariableName: "Resp"},
}
got := e.formatRestCallAction(action)
assertContains(t, got, "header 'Authorization' = 'Bearer ' + $Token")
}
func TestFormatRestCallAction_WithAuth(t *testing.T) {
e := newTestExecutor()
action := µflows.RestCallAction{
HttpConfiguration: µflows.HttpConfiguration{
HttpMethod: microflows.HttpMethodGet,
LocationTemplate: "https://api.example.com",
UseAuthentication: true,
Username: "'admin'",
Password: "'secret'",
},
ResultHandling: µflows.ResultHandlingString{},
}
got := e.formatRestCallAction(action)
assertContains(t, got, "auth basic 'admin' password 'secret'")
}
func TestFormatRestCallAction_WithTimeout(t *testing.T) {
e := newTestExecutor()
action := µflows.RestCallAction{
HttpConfiguration: µflows.HttpConfiguration{
HttpMethod: microflows.HttpMethodGet,
LocationTemplate: "https://api.example.com",
},
TimeoutExpression: "30",
ResultHandling: µflows.ResultHandlingString{},
}
got := e.formatRestCallAction(action)
assertContains(t, got, "timeout 30")
}