1
|
|
|
package e2e |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"net/http" |
6
|
|
|
"testing" |
7
|
|
|
|
8
|
|
|
"github.com/stretchr/testify/assert" |
9
|
|
|
) |
10
|
|
|
|
11
|
|
|
//func randomString(length int) string { |
12
|
|
|
// generator := rand.New(rand.NewSource(time.Now().UnixNano())) |
13
|
|
|
// b := make([]byte, length+2) |
14
|
|
|
// generator.Read(b) |
15
|
|
|
// return fmt.Sprintf("%x", b)[2 : length+2] |
16
|
|
|
//} |
17
|
|
|
|
18
|
|
|
//func TestDiscountsService_Create(t *testing.T) { |
19
|
|
|
// // Act |
20
|
|
|
// storeID := "11559" |
21
|
|
|
// discount, response, err := client.Discounts.Create(context.Background(), &lemonsqueezy.DiscountCreateParams{ |
22
|
|
|
// Name: "10% Off", |
23
|
|
|
// Code: strings.ToUpper(randomString(10)), |
24
|
|
|
// Amount: 10, |
25
|
|
|
// AmountType: "percent", |
26
|
|
|
// StoreID: storeID, |
27
|
|
|
// }) |
28
|
|
|
// |
29
|
|
|
// // Assert |
30
|
|
|
// assert.Nil(t, err) |
31
|
|
|
// |
32
|
|
|
// assert.Equal(t, http.StatusCreated, response.HTTPResponse.StatusCode) |
33
|
|
|
// assert.Equal(t, storeID, fmt.Sprintf("%d", discount.Data.Attributes.StoreID)) |
34
|
|
|
// |
35
|
|
|
// // Teardown |
36
|
|
|
// //_, _ = client.Discounts.Delete(context.Background(), discount.Data.ID) |
37
|
|
|
//} |
38
|
|
|
|
39
|
|
|
//func TestDiscountsService_Get(t *testing.T) { |
40
|
|
|
// // Arrange |
41
|
|
|
// //storeID := "11559" |
42
|
|
|
// //expectedDiscount, response, err := client.Discounts.Create(context.Background(), &lemonsqueezy.DiscountCreateParams{ |
43
|
|
|
// // Name: "10% Off", |
44
|
|
|
// // Code: strings.ToUpper(randomString(10)), |
45
|
|
|
// // Amount: 10, |
46
|
|
|
// // AmountType: "percent", |
47
|
|
|
// // StoreID: storeID, |
48
|
|
|
// //}) |
49
|
|
|
// |
50
|
|
|
// //spew.Dump(expectedDiscount.Data.ID) |
51
|
|
|
// |
52
|
|
|
// // Act |
53
|
|
|
// discount, response, err := client.Discounts.Get(context.Background(), "11199") //expectedDiscount.Data.ID) |
54
|
|
|
// |
55
|
|
|
// spew.Dump(discount) |
56
|
|
|
// |
57
|
|
|
// // Assert |
58
|
|
|
// assert.Nil(t, err) |
59
|
|
|
// |
60
|
|
|
// assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
61
|
|
|
// //assert.Equal(t, expectedDiscount.Data.ID, discount.Data.ID) |
62
|
|
|
// |
63
|
|
|
// // Teardown |
64
|
|
|
// //_, _ = client.Discounts.Delete(context.Background(), discount.Data.ID) |
65
|
|
|
//} |
66
|
|
|
//func TestDiscountsService_Delete(t *testing.T) { |
67
|
|
|
// // Arrange |
68
|
|
|
// storeID := "11559" |
69
|
|
|
// expectedDiscount, response, err := client.Discounts.Create(context.Background(), &lemonsqueezy.DiscountCreateParams{ |
70
|
|
|
// Name: "10% Off", |
71
|
|
|
// Code: strings.ToUpper(randomString(10)), |
72
|
|
|
// Amount: 10, |
73
|
|
|
// AmountType: "percent", |
74
|
|
|
// StoreID: storeID, |
75
|
|
|
// }) |
76
|
|
|
// |
77
|
|
|
// // Act |
78
|
|
|
// response, err = client.Discounts.Delete(context.Background(), expectedDiscount.Data.ID) |
79
|
|
|
// |
80
|
|
|
// // Assert |
81
|
|
|
// assert.Nil(t, err) |
82
|
|
|
// |
83
|
|
|
// assert.Equal(t, http.StatusNoContent, response.HTTPResponse.StatusCode) |
84
|
|
|
//} |
85
|
|
|
|
86
|
|
|
func TestDiscountsService_List(t *testing.T) { |
87
|
|
|
// Act |
88
|
|
|
discounts, response, err := client.Discounts.List(context.Background()) |
89
|
|
|
|
90
|
|
|
// Assert |
91
|
|
|
assert.Nil(t, err) |
92
|
|
|
|
93
|
|
|
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
94
|
|
|
assert.Equal(t, 0, len(discounts.Data)) |
95
|
|
|
} |
96
|
|
|
|