-
Notifications
You must be signed in to change notification settings - Fork 15
/
hellosign_test.go
118 lines (109 loc) · 2.66 KB
/
hellosign_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
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
111
112
113
114
115
116
117
118
package hellosign
import (
"fmt"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"
)
func TestCreateEmbeddedSignatureRequestNotReturnNil(t *testing.T) {
mockClient, mockServer := createMockClient("1234")
defer mockServer.Close()
embReq := createEmbeddedRequest()
res, err := mockClient.CreateEmbeddedSignatureRequest(embReq)
assert.Nil(t, err, "Should not return error")
assert.NotNil(t, res, "Should return response")
}
// Private Functions
func createMockClient(key string) (Client, *httptest.Server) {
mockServer := createMockServer(201, "Everything is cool")
transport := &http.Transport{
Proxy: func(req *http.Request) (*url.URL, error) {
return url.Parse(mockServer.URL)
},
}
mockHTTPClient := &http.Client{Transport: transport}
client := Client{
APIKey: key,
BaseURL: mockServer.URL,
HTTPClient: mockHTTPClient,
}
return client, mockServer
}
func createMockServer(status int, body string) *httptest.Server {
testServer := httptest.NewServer(createMockHandler(status, body))
return testServer
}
func createMockHandler(status int, body string) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(status)
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, body)
})
}
func createEmbeddedRequest() EmbeddedRequest {
fileOne, _ := os.Open("fixtures/offer_letter.pdf")
fileOne.Close()
fileTwo, _ := os.Open("fixtures/offer_letter.pdf")
fileTwo.Close()
return EmbeddedRequest{
TestMode: true,
ClientId: "0987",
File: []*os.File{
fileOne,
fileTwo,
},
Title: "cool title",
Subject: "awesome",
Message: "cool message bro",
SigningRedirectURL: "example signing redirect url",
Signers: []Signer{
Signer{
Email: "[email protected]",
Name: "Freddy Rangel",
},
Signer{
Email: "[email protected]",
Name: "Frederick Rangel",
},
},
CCEmailAddresses: []string{
},
UseTextTags: false,
HideTextTags: true,
Metadata: map[string]string{
"no": "cats",
"more": "dogs",
},
FormFieldsPerDocument: [][]DocumentFormField{
[]DocumentFormField{
DocumentFormField{
APIId: "api_id",
Name: "display name",
Type: "text",
X: 123,
Y: 456,
Width: 678,
Required: true,
Signer: 0,
},
},
[]DocumentFormField{
DocumentFormField{
APIId: "api_id_2",
Name: "display name 2",
Type: "text 2",
X: 123,
Y: 456,
Width: 678,
Required: true,
Signer: 1,
},
},
},
}
}