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