forked from guilhermebr/go-stone-openbank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpix_entries_test.go
73 lines (59 loc) · 1.68 KB
/
pix_entries_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
package openbank
import (
"fmt"
"net/http"
"reflect"
"testing"
"github.com/stone-co/go-stone-openbank/types"
)
func TestCreateEntry(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/api/v1/pix/8cbeb3d2-750f-4b14-81a1-143ad715c273/entries", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
response := `
{
"verification_id": "a123456"
}`
fmt.Fprint(w, response)
})
input := types.CreatePixEntryInput{
AccountID: "8cbeb3d2-750f-4b14-81a1-143ad715c273",
Key: "[email protected]",
KeyType: "email",
}
data, _, err := client.Pix.CreateEntry(input, "idempotencyKey123")
if err != nil {
t.Errorf("pix.CreateEntry returned error: %v", err)
}
expected := CreatePixEntryOutput{VerificationID: "a123456"}
if !reflect.DeepEqual(data, expected) {
t.Errorf("pix.CrateEntry returned %+v, expected %+v", data, expected)
}
}
func TestCreateEntryWithVerification(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/api/v1/pix/8cbeb3d2-750f-4b14-81a1-143ad715c273/entries", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
response := `
{
"id": "abcd123"
}`
fmt.Fprint(w, response)
})
input := types.CreatePixEntryInput{
AccountID: "8cbeb3d2-750f-4b14-81a1-143ad715c273",
Key: "[email protected]",
KeyType: "email",
VerificationID: "a123456",
}
data, _, err := client.Pix.CreateEntry(input, "idempotencyKey123")
if err != nil {
t.Errorf("pix.CreateEntry returned error: %v", err)
}
expected := CreatePixEntryOutput{ID: "abcd123"}
if !reflect.DeepEqual(data, expected) {
t.Errorf("pix.CrateEntry returned %+v, expected %+v", data, expected)
}
}