|
6 | 6 | "encoding/json" |
7 | 7 | "fmt" |
8 | 8 | "net/http" |
| 9 | + "net/http/httptest" |
9 | 10 | "testing" |
10 | 11 | "time" |
11 | 12 |
|
@@ -198,7 +199,14 @@ func TestParseUnknownEventNotificationWithRelatedObject(t *testing.T) { |
198 | 199 | }` |
199 | 200 |
|
200 | 201 | // Create mock server that expects a GET to /v1/related_objects/ro_123 |
201 | | - server := MockServerWithStripeContext(t, http.MethodGet, "/v1/related_objects/ro_123", "ctx_123", nil, relatedObjectResp) |
| 202 | + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 203 | + assert.Equal(t, http.MethodGet, r.Method) |
| 204 | + assert.Equal(t, "/v1/related_objects/ro_123", r.URL.Path) |
| 205 | + assert.Equal(t, "Bearer "+TestAPIKey, r.Header.Get("Authorization")) |
| 206 | + assert.Equal(t, "ctx_123", r.Header.Get("Stripe-Context")) |
| 207 | + assert.Equal(t, "event=evt_test_webhook", r.Header.Get("Stripe-Request-Trigger")) |
| 208 | + w.Write([]byte(relatedObjectResp)) |
| 209 | + })) |
202 | 210 | defer server.Close() |
203 | 211 |
|
204 | 212 | // Create client with custom backend pointing to mock server |
@@ -262,7 +270,14 @@ func TestFetchEventHTTPCall(t *testing.T) { |
262 | 270 | }` |
263 | 271 |
|
264 | 272 | // Create mock server that expects a GET to /v2/core/events/evt_123 |
265 | | - server := MockServerWithStripeContext(t, http.MethodGet, "/v2/core/events/evt_123", "ctx_123", nil, mockEventResponse) |
| 273 | + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 274 | + assert.Equal(t, http.MethodGet, r.Method) |
| 275 | + assert.Equal(t, "/v2/core/events/evt_123", r.URL.Path) |
| 276 | + assert.Equal(t, "Bearer "+TestAPIKey, r.Header.Get("Authorization")) |
| 277 | + assert.Equal(t, "ctx_123", r.Header.Get("Stripe-Context")) |
| 278 | + assert.Equal(t, "event=evt_123", r.Header.Get("Stripe-Request-Trigger")) |
| 279 | + w.Write([]byte(mockEventResponse)) |
| 280 | + })) |
266 | 281 | defer server.Close() |
267 | 282 |
|
268 | 283 | // Create client with custom backend pointing to mock server |
@@ -319,7 +334,13 @@ func TestFetchRelatedObject(t *testing.T) { |
319 | 334 | }` |
320 | 335 |
|
321 | 336 | // Create mock server that expects a GET to /v1/billing/meters/bm_123 |
322 | | - server := MockServer(t, http.MethodGet, "/v1/billing/meters/bm_123", nil, mockRelatedObjectResponse) |
| 337 | + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 338 | + assert.Equal(t, http.MethodGet, r.Method) |
| 339 | + assert.Equal(t, "/v1/billing/meters/bm_123", r.URL.Path) |
| 340 | + assert.Equal(t, "Bearer "+TestAPIKey, r.Header.Get("Authorization")) |
| 341 | + assert.Equal(t, "event=evt_123", r.Header.Get("Stripe-Request-Trigger")) |
| 342 | + w.Write([]byte(mockRelatedObjectResponse)) |
| 343 | + })) |
323 | 344 | defer server.Close() |
324 | 345 |
|
325 | 346 | // Create client with custom backend pointing to mock server |
@@ -385,7 +406,14 @@ func TestFetchRelatedObjectUnknownEvent(t *testing.T) { |
385 | 406 |
|
386 | 407 | // Create mock server that expects a GET to /v1/billing/meters/bm_123 |
387 | 408 | // it also checks that stripe-context is correct |
388 | | - server := MockServerWithStripeContext(t, http.MethodGet, "/v1/billing/meters/bm_123", "ctx_123", nil, mockRelatedObjectResponse) |
| 409 | + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 410 | + assert.Equal(t, http.MethodGet, r.Method) |
| 411 | + assert.Equal(t, "/v1/billing/meters/bm_123", r.URL.Path) |
| 412 | + assert.Equal(t, "Bearer "+TestAPIKey, r.Header.Get("Authorization")) |
| 413 | + assert.Equal(t, "ctx_123", r.Header.Get("Stripe-Context")) |
| 414 | + assert.Equal(t, "event=evt_123", r.Header.Get("Stripe-Request-Trigger")) |
| 415 | + w.Write([]byte(mockRelatedObjectResponse)) |
| 416 | + })) |
389 | 417 | defer server.Close() |
390 | 418 |
|
391 | 419 | // Create client with custom backend pointing to mock server |
|
0 commit comments