-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathwebhook_endpoint_test.go
More file actions
72 lines (63 loc) · 2.71 KB
/
Copy pathwebhook_endpoint_test.go
File metadata and controls
72 lines (63 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package lago_test
import (
"context"
"testing"
qt "github.com/frankban/quicktest"
. "github.com/getlago/lago-go-client"
lt "github.com/getlago/lago-go-client/testing"
)
var mockWebhookEndpointResponse = map[string]any{
"webhook_endpoint": map[string]any{
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"lago_organization_id": "2b902b90-2b90-2b90-2b90-2b902b902b90",
"webhook_url": "https://example.com/webhook",
"signature_algo": "jwt",
"name": "My Webhook Endpoint",
"event_types": []string{"customer.created"},
"created_at": "2025-01-01T10:00:00Z",
},
}
func TestWebhookEndpointRequest_Create(t *testing.T) {
t.Run("Wraps the body under the webhook_endpoint key", func(t *testing.T) {
c := qt.New(t)
server := lt.NewMockServer(c).
MatchMethod("POST").
MatchPath("/api/v1/webhook_endpoints").
MatchJSONBody(`{"webhook_endpoint":{"webhook_url":"https://example.com/webhook","signature_algo":"jwt","name":"My Webhook Endpoint","event_types":["customer.created"]}}`).
MockResponse(mockWebhookEndpointResponse)
defer server.Close()
name := "My Webhook Endpoint"
result, err := server.Client().WebhookEndpoint().Create(context.Background(), &WebhookEndpointInput{
WebhookURL: "https://example.com/webhook",
SignatureAlgo: JWT,
Name: &name,
EventTypes: []string{"customer.created"},
})
c.Assert(err == nil, qt.IsTrue)
c.Assert(result.WebhookURL, qt.Equals, "https://example.com/webhook")
c.Assert(*result.Name, qt.Equals, "My Webhook Endpoint")
c.Assert(result.EventTypes, qt.DeepEquals, []string{"customer.created"})
})
}
func TestWebhookEndpointRequest_Update(t *testing.T) {
t.Run("Wraps the body under the webhook_endpoint key", func(t *testing.T) {
c := qt.New(t)
server := lt.NewMockServer(c).
MatchMethod("PUT").
MatchPath("/api/v1/webhook_endpoints/1a901a90-1a90-1a90-1a90-1a901a901a90").
MatchJSONBody(`{"webhook_endpoint":{"webhook_url":"https://example.com/webhook","signature_algo":"jwt","name":"My Webhook Endpoint","event_types":["customer.created"]}}`).
MockResponse(mockWebhookEndpointResponse)
defer server.Close()
name := "My Webhook Endpoint"
result, err := server.Client().WebhookEndpoint().Update(context.Background(), &WebhookEndpointInput{
WebhookURL: "https://example.com/webhook",
SignatureAlgo: JWT,
Name: &name,
EventTypes: []string{"customer.created"},
}, "1a901a90-1a90-1a90-1a90-1a901a901a90")
c.Assert(err == nil, qt.IsTrue)
c.Assert(result.WebhookURL, qt.Equals, "https://example.com/webhook")
c.Assert(*result.Name, qt.Equals, "My Webhook Endpoint")
c.Assert(result.EventTypes, qt.DeepEquals, []string{"customer.created"})
})
}