Passed
Push — main ( 2b8b96...6e7fbc )
by Acho
01:19
created

e2e/webhooks_service_test.go   A

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
dl 0
loc 101
rs 10
c 0
b 0
f 0

1 Method

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