1
|
|
|
package client |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"encoding/json" |
5
|
|
|
"testing" |
6
|
|
|
"time" |
7
|
|
|
|
8
|
|
|
"github.com/NdoleStudio/lemonsqueezy-go/internal/stubs" |
9
|
|
|
"github.com/stretchr/testify/assert" |
10
|
|
|
) |
11
|
|
|
|
12
|
|
|
func TestWebhook(t *testing.T) { |
13
|
|
|
// Setup |
14
|
|
|
t.Parallel() |
15
|
|
|
|
16
|
|
|
var request webhookRequest[OrderCreatedWebhookRequestAttributes, OrderCreatedWebhookRequestRelationships] |
17
|
|
|
err := json.Unmarshal(stubs.WebhookRequest(), &request) |
18
|
|
|
assert.Nil(t, err) |
19
|
|
|
|
20
|
|
|
assert.Equal(t, webhookRequest[OrderCreatedWebhookRequestAttributes, OrderCreatedWebhookRequestRelationships]{ |
21
|
|
|
Meta: WebhookRequestMeta{ |
22
|
|
|
EventName: "order_created", |
23
|
|
|
TestMode: false, |
24
|
|
|
CustomData: map[string]interface{}(nil), |
25
|
|
|
}, |
26
|
|
|
Data: WebhookRequestData[OrderCreatedWebhookRequestAttributes, OrderCreatedWebhookRequestRelationships]{ |
27
|
|
|
Type: "orders", |
28
|
|
|
ID: "1", |
29
|
|
|
Attributes: OrderCreatedWebhookRequestAttributes{ |
30
|
|
|
StoreID: 1, |
31
|
|
|
Identifier: "636f855c-1fb9-4c07-b75c-3a10afef010a", |
32
|
|
|
OrderNumber: 1, |
33
|
|
|
UserName: "Darlene Daugherty", |
34
|
|
|
UserEmail: "[email protected]", |
35
|
|
|
Currency: "USD", |
36
|
|
|
CurrencyRate: "1.0000", |
37
|
|
|
Subtotal: 999, |
38
|
|
|
DiscountTotal: 0, |
39
|
|
|
Tax: 200, |
40
|
|
|
Total: 1199, |
41
|
|
|
SubtotalUsd: 999, |
42
|
|
|
DiscountTotalUsd: 0, |
43
|
|
|
TaxUsd: 200, |
44
|
|
|
TotalUsd: 1199, |
45
|
|
|
TaxName: "VAT", |
46
|
|
|
TaxRate: "20.00", |
47
|
|
|
Status: "paid", |
48
|
|
|
StatusFormatted: "Paid", |
49
|
|
|
Refunded: false, |
50
|
|
|
RefundedAt: nil, |
51
|
|
|
CreatedAt: time.Date(2021, time.August, 11, 13, 47, 29, 0, time.UTC), |
52
|
|
|
UpdatedAt: time.Date(2021, time.August, 11, 13, 54, 54, 0, time.UTC), |
53
|
|
|
}, |
54
|
|
|
Relationships: OrderCreatedWebhookRequestRelationships{ |
55
|
|
|
Store: ApiResponseLinks{ |
56
|
|
|
Links: ApiResponseLink{ |
57
|
|
|
Related: "https://api.lemonsqueezy.com/v1/orders/1/store", |
58
|
|
|
Self: "https://api.lemonsqueezy.com/v1/orders/1/relationships/store", |
59
|
|
|
}, |
60
|
|
|
}, |
61
|
|
|
OrderItem: ApiResponseLinks{ |
62
|
|
|
Links: ApiResponseLink{ |
63
|
|
|
Related: "https://api.lemonsqueezy.com/v1/orders/1/order-items", |
64
|
|
|
Self: "https://api.lemonsqueezy.com/v1/orders/1/relationships/order-items", |
65
|
|
|
}, |
66
|
|
|
}, |
67
|
|
|
Subscriptions: ApiResponseLinks{ |
68
|
|
|
Links: ApiResponseLink{ |
69
|
|
|
Related: "https://api.lemonsqueezy.com/v1/orders/1/subscriptions", |
70
|
|
|
Self: "https://api.lemonsqueezy.com/v1/orders/1/relationships/subscriptions", |
71
|
|
|
}, |
72
|
|
|
}, |
73
|
|
|
LicenseKeys: ApiResponseLinks{ |
74
|
|
|
Links: ApiResponseLink{ |
75
|
|
|
Related: "https://api.lemonsqueezy.com/v1/orders/1/license-keys", |
76
|
|
|
Self: "https://api.lemonsqueezy.com/v1/orders/1/relationships/license-keys", |
77
|
|
|
}, |
78
|
|
|
}, |
79
|
|
|
}, |
80
|
|
|
Links: ApiResponseLink{ |
81
|
|
|
Self: "https://api.lemonsqueezy.com/v1/orders/1", |
82
|
|
|
}, |
83
|
|
|
}, |
84
|
|
|
}, request) |
85
|
|
|
} |
86
|
|
|
|