-
Notifications
You must be signed in to change notification settings - Fork 3
/
checkout_test.go
60 lines (53 loc) · 1.93 KB
/
checkout_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
package mercadopago_test
import (
"fmt"
"testing"
"github.com/gpascual2/mp-sdk-go"
)
var prefBase *mercadopago.Preference
var prefCreated *mercadopago.Preference
var err error
func init() {
prefBase = &mercadopago.Preference{
ExternalReference: "ExRef",
}
prefBase.Payer.Name = "Jon"
prefBase.Payer.Surname = "Snow"
prefBase.Payer.Email = "[email protected]"
prefBase.Items = append(prefBase.Items, mercadopago.Item{
ID: "Item1_ID",
Title: "Item1_title",
Quantity: 1,
CurrencyID: "ARS",
UnitPrice: 10.2,
})
prefBase.PaymentMethods.Installments = 1
prefBase.PaymentMethods.ExcludedPaymentTypes = append(prefBase.PaymentMethods.ExcludedPaymentTypes, mercadopago.ID{ID: "ticket"})
prefBase.PaymentMethods.ExcludedPaymentTypes = append(prefBase.PaymentMethods.ExcludedPaymentTypes, mercadopago.ID{ID: "atm"})
}
// TestCreatePreference - A checkout preference should be obtained from MercadoPago API
func TestCreatePreference(t *testing.T) {
fmt.Println("mp_test : CreatePreference")
prefCreated, err = mp.CreatePreference(prefBase)
if err != nil {
t.Fatalf("Error creating a checkout preference: %v", err)
}
if prefCreated.InitPoint == "" {
t.Errorf("Expected InitPoint to contain a value and is empty")
}
fmt.Println("SandBox init: ", prefCreated.SandboxInitPoint)
if prefCreated.Items[0] != prefBase.Items[0] {
t.Errorf("Expected Preference Item to equal the requested one. Sent: %v / Got: %v", prefBase.Items[0], prefCreated.Items[0])
}
}
// TestGetPreference - A checkout preference should be obtained from MercadoPago API
func TestGetPreference(t *testing.T) {
fmt.Println("mp_test : GetPreference")
prefGet, err := mp.GetPreference(prefCreated.ID)
if err != nil {
t.Fatalf("Error getting the checkout preference: %v", err)
}
if prefGet.Items[0] != prefBase.Items[0] {
t.Errorf("Expected Preference Item to equal the requested one. Sent: %v / Got: %v", prefBase.Items[0], prefGet.Items[0])
}
}