-
Notifications
You must be signed in to change notification settings - Fork 10
/
order_refund_test.go
79 lines (73 loc) · 2.2 KB
/
order_refund_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
package woocommerce
import (
"errors"
"github.com/hiscaler/gox/jsonx"
"github.com/stretchr/testify/assert"
"testing"
)
func TestOrderRefundService_All(t *testing.T) {
t.Run("getOrderId", getOrderId)
params := OrderRefundsQueryParams{}
items, _, _, _, err := wooClient.Services.OrderRefund.All(orderId, params)
if err != nil {
t.Errorf("wooClient.Services.OrderRefund.All error: %s", err.Error())
} else {
if len(items) > 0 {
childId = items[0].ID
}
t.Logf("items = %s", jsonx.ToPrettyJson(items))
}
}
func TestOrderRefundService_Create(t *testing.T) {
t.Run("getOrderId", getOrderId)
req := CreateOrderRefundRequest{
Amount: 1,
Reason: "product is lost",
RefundedBy: 0,
MetaData: nil,
LineItems: nil,
}
item, err := wooClient.Services.OrderRefund.Create(mainId, req)
if err != nil {
t.Fatalf("wooClient.Services.OrderRefund.Create error: %s", err.Error())
} else {
assert.Equal(t, 100.00, item.Amount, "refund amount")
childId = item.ID
}
}
func TestOrderRefundService_One(t *testing.T) {
t.Run("TestOrderRefundService_All", TestOrderRefundService_All)
item, err := wooClient.Services.OrderRefund.One(mainId, childId, 2)
if err != nil {
t.Errorf("wooClient.Services.OrderRefund.One(%d, %d) error: %s", orderId, noteId, err.Error())
} else {
assert.Equal(t, childId, item.ID, "note id")
}
}
func TestOrderRefundService_CreateDelete(t *testing.T) {
t.Run("getOrderId", getOrderId)
req := CreateOrderRefundRequest{
Amount: 100,
Reason: "product is lost",
RefundedBy: 0,
MetaData: nil,
LineItems: nil,
}
item, err := wooClient.Services.OrderRefund.Create(mainId, req)
if err != nil {
t.Fatalf("wooClient.Services.OrderRefund.Create error: %s", err.Error())
} else {
assert.Equal(t, 100.00, item.Amount, "refund amount")
noteId = item.ID
}
// Delete
_, err = wooClient.Services.OrderNote.Delete(mainId, childId, true)
if err != nil {
t.Fatalf("wooClient.Services.OrderRefund.Delete(%d, %d, %v) error: %s", mainId, childId, true, err.Error())
} else {
_, err = wooClient.Services.OrderNote.One(mainId, childId)
if !errors.Is(err, ErrNotFound) {
t.Fatalf("wooClient.Services.OrderRefund.Delete(%d, %d, %v) failed", mainId, childId, true)
}
}
}