-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpayment_gateway_test.go
56 lines (48 loc) · 1.73 KB
/
payment_gateway_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
package woocommerce
import (
"github.com/brianvoe/gofakeit/v6"
"github.com/hiscaler/woocommerce-go/entity"
"github.com/stretchr/testify/assert"
"testing"
)
var paymentGatewayId string
func TestPaymentGatewayService_All(t *testing.T) {
items, err := wooClient.Services.PaymentGateway.All()
if err != nil {
t.Fatalf("wooClient.Services.PaymentGateway.All error: %s", err.Error())
}
if len(items) > 0 {
paymentGatewayId = items[0].ID
}
}
func TestPaymentGatewayService_One(t *testing.T) {
t.Run("TestPaymentGatewayService_All", TestPaymentGatewayService_All)
item, err := wooClient.Services.PaymentGateway.One(paymentGatewayId)
if err != nil {
t.Errorf("wooClient.Services.Coupon.PaymentGateway error: %s", err.Error())
} else {
assert.Equal(t, paymentGatewayId, item.ID, "payment gateway id")
}
}
func TestPaymentGatewayService_Update(t *testing.T) {
t.Run("TestPaymentGatewayService_All", TestPaymentGatewayService_All)
var oldItem, newItem entity.PaymentGateway
var err error
oldItem, err = wooClient.Services.PaymentGateway.One(paymentGatewayId)
if err != nil {
t.Fatalf("wooClient.Services.PaymentGateway.One error: %s", err.Error())
}
req := UpdatePaymentGatewayRequest{}
newItem, err = wooClient.Services.PaymentGateway.Update(paymentGatewayId, req)
if err != nil {
t.Fatalf("wooClient.Services.PaymentGateway.Update error: %s", err.Error())
}
assert.Equal(t, oldItem, newItem, "all no change")
// Change title
req.Title = gofakeit.RandomString([]string{"A", "B", "C", "D", "E", "F", "G"})
newItem, err = wooClient.Services.PaymentGateway.Update(paymentGatewayId, req)
if err != nil {
t.Fatalf("wooClient.Services.PaymentGateway.Update error: %s", err.Error())
}
assert.Equal(t, req.Title, newItem.Title, "title")
}