1
|
|
|
package e2e |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"fmt" |
6
|
|
|
"net/http" |
7
|
|
|
"testing" |
8
|
|
|
"time" |
9
|
|
|
|
10
|
|
|
lemonsqueezy "github.com/NdoleStudio/lemonsqueezy-go" |
11
|
|
|
"github.com/stretchr/testify/assert" |
12
|
|
|
) |
13
|
|
|
|
14
|
|
|
func TestCheckoutsService_Create(t *testing.T) { |
15
|
|
|
// Act |
16
|
|
|
storeID := "11559" |
17
|
|
|
checkout, response, err := client.Checkouts.Create(context.Background(), &lemonsqueezy.CheckoutCreateParams{ |
18
|
|
|
CustomPrice: 5000, |
19
|
|
|
EnabledVariants: []int{36096}, |
20
|
|
|
ButtonColor: "#2DD272", |
21
|
|
|
CustomData: map[string]string{"user_id": "123"}, |
22
|
|
|
ExpiresAt: time.Now().UTC().Add(time.Hour * 24), |
23
|
|
|
StoreID: storeID, |
24
|
|
|
VariantID: "36096", |
25
|
|
|
}) |
26
|
|
|
|
27
|
|
|
// Assert |
28
|
|
|
assert.Nil(t, err) |
29
|
|
|
|
30
|
|
|
assert.Equal(t, http.StatusCreated, response.HTTPResponse.StatusCode) |
31
|
|
|
assert.Equal(t, storeID, fmt.Sprintf("%d", checkout.Data.Attributes.StoreID)) |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
func TestCheckoutsService_Get(t *testing.T) { |
35
|
|
|
// Arrange |
36
|
|
|
checkoutID := "b75461df-3832-4ec3-b7d3-f371a07a4eaa" |
37
|
|
|
|
38
|
|
|
// Act |
39
|
|
|
checkout, response, err := client.Checkouts.Get(context.Background(), checkoutID) |
40
|
|
|
|
41
|
|
|
// Assert |
42
|
|
|
assert.Nil(t, err) |
43
|
|
|
|
44
|
|
|
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
45
|
|
|
assert.Equal(t, checkoutID, checkout.Data.ID) |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
func TestCheckoutsService_List(t *testing.T) { |
49
|
|
|
// Act |
50
|
|
|
checkouts, response, err := client.Checkouts.List(context.Background()) |
51
|
|
|
|
52
|
|
|
// Assert |
53
|
|
|
assert.Nil(t, err) |
54
|
|
|
|
55
|
|
|
assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
56
|
|
|
assert.GreaterOrEqual(t, 10, len(checkouts.Data)) |
57
|
|
|
} |
58
|
|
|
|