Passed
Push — main ( 6599d2...81bd35 )
by Acho
01:34
created

e2e.TestDiscountsService_List   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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