-
Notifications
You must be signed in to change notification settings - Fork 10
/
order_note_test.go
73 lines (67 loc) · 2.03 KB
/
order_note_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 woocommerce
import (
"errors"
"github.com/brianvoe/gofakeit/v6"
"github.com/hiscaler/gox/jsonx"
"github.com/stretchr/testify/assert"
"testing"
)
func TestOrderNoteService_All(t *testing.T) {
t.Run("getOrderId", getOrderId)
params := OrderNotesQueryParams{}
items, _, _, _, err := wooClient.Services.OrderNote.All(orderId, params)
if err != nil {
t.Errorf("wooClient.Services.OrderNote.All error: %s", err.Error())
} else {
if len(items) > 0 {
noteId = items[0].ID
}
t.Logf("items = %s", jsonx.ToPrettyJson(items))
}
}
func TestOrderNoteService_Create(t *testing.T) {
note := gofakeit.Address().Address
req := CreateOrderNoteRequest{
Note: note,
}
item, err := wooClient.Services.OrderNote.Create(orderId, req)
if err != nil {
t.Fatalf("wooClient.Services.OrderNote.Create error: %s", err.Error())
} else {
assert.Equal(t, note, item.Note, "note")
noteId = item.ID
}
}
func TestOrderNoteService_One(t *testing.T) {
t.Run("TestOrderNoteService_All", TestOrderNoteService_All)
item, err := wooClient.Services.OrderNote.One(orderId, noteId)
if err != nil {
t.Errorf("wooClient.Services.OrderNote.One(%d, %d) error: %s", orderId, noteId, err.Error())
} else {
assert.Equal(t, noteId, item.ID, "note id")
}
}
func TestOrderNoteService_CreateDelete(t *testing.T) {
t.Run("getOrderId", getOrderId)
note := gofakeit.Address().Address
req := CreateOrderNoteRequest{
Note: note,
}
item, err := wooClient.Services.OrderNote.Create(orderId, req)
if err != nil {
t.Fatalf("wooClient.Services.OrderNote.Create error: %s", err.Error())
} else {
assert.Equal(t, note, item.Note, "note")
noteId = item.ID
}
// Delete
_, err = wooClient.Services.OrderNote.Delete(orderId, noteId, true)
if err != nil {
t.Fatalf("wooClient.Services.OrderNote.Delete(%d, %d, %v) error: %s", orderId, noteId, true, err.Error())
} else {
_, err = wooClient.Services.OrderNote.One(orderId, noteId)
if !errors.Is(err, ErrNotFound) {
t.Fatalf("wooClient.Services.OrderNote.Delete(%d, %d, %v) failed", orderId, noteId, true)
}
}
}