Skip to content

Commit 87b309a

Browse files
authored
chore: Webhook integration tests (#69)
1 parent 9a15e0c commit 87b309a

File tree

6 files changed

+454
-2
lines changed

6 files changed

+454
-2
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{
2+
"id": "TDWJ6DrYJAhm",
3+
"created_at": "2025-01-08T08:19:20.763280+00:00",
4+
"type": "<invoice.type>",
5+
"properties": {
6+
"automatically_marked_as_paid": false
7+
},
8+
"invoice": {
9+
"amount_due": "25.00",
10+
"auto_collection": {
11+
"enabled": true,
12+
"next_attempt_at": null,
13+
"num_attempts": 1,
14+
"previously_attempted_at": "2025-01-08T08:06:21+00:00"
15+
},
16+
"billing_address": null,
17+
"created_at": "2024-11-08T12:07:13+00:00",
18+
"credit_notes": [],
19+
"currency": "USD",
20+
"customer": {
21+
"external_customer_id": "test_customer_12345",
22+
"id": "aAsPoaKuX9DR4"
23+
},
24+
"customer_balance_transactions": [],
25+
"customer_tax_id": null,
26+
"discount": {
27+
"applies_to_price_ids": [
28+
"3LULTJweU496FVL",
29+
"6DCYxjXtDavvagD",
30+
"84WaufbVHiusXpv",
31+
"AJhqCkQz7iXDsUV",
32+
"HsMS8buA2AgeEg",
33+
"Nfzp2zMSnVS6iX",
34+
"Q7FtwPSEdYf85y",
35+
"YjQhN4gxKBzqth",
36+
"bV9wPpTUyLz76w",
37+
"ht7Ts7PV8VgXSX"
38+
],
39+
"discount_type": "percentage",
40+
"percentage_discount": 1,
41+
"reason": null
42+
},
43+
"discounts": [
44+
{
45+
"applies_to_price_ids": [
46+
"3LULTJweU496FVL",
47+
"6DCYxjXtDavvagD",
48+
"84WaufbVHiusXpv",
49+
"AJhqCkQz7iXDsUV",
50+
"HsMS8buA2AgeEg",
51+
"Nfzp2zMSnVS6iX",
52+
"Q7FtwPSEdYf85y",
53+
"YjQhN4gxKBzqth",
54+
"bV9wPpTUyLz76w",
55+
"ht7Ts7PV8VgXSX"
56+
],
57+
"discount_type": "percentage",
58+
"percentage_discount": 1,
59+
"reason": null
60+
}
61+
],
62+
"due_date": "2025-01-08T00:00:00+00:00",
63+
"eligible_to_issue_at": null,
64+
"id": "hNmWV3yQnGx9v",
65+
"invoice_date": "2025-01-08T00:00:00+00:00",
66+
"invoice_number": "TEST-2025-001",
67+
"invoice_source": "subscription",
68+
"issue_failed_at": null,
69+
"issued_at": "2025-01-08T08:06:13+00:00",
70+
"line_items": [
71+
{
72+
"amount": "25.00",
73+
"discount": null,
74+
"end_date": "2025-02-08T00:00:00+00:00",
75+
"grouping": null,
76+
"id": "YiD4evZC3JgEpy",
77+
"maximum": null,
78+
"maximum_amount": null,
79+
"minimum": null,
80+
"minimum_amount": null,
81+
"name": "Pro Plan",
82+
"price": {
83+
"billable_metric": null,
84+
"billing_cycle_configuration": {
85+
"duration": 1,
86+
"duration_unit": "month"
87+
},
88+
"cadence": "monthly",
89+
"conversion_rate": null,
90+
"created_at": "2024-08-06T03:22:41+00:00",
91+
"credit_allocation": null,
92+
"currency": "USD",
93+
"dimensional_price_configuration": null,
94+
"discount": null,
95+
"external_price_id": null,
96+
"fixed_price_quantity": 1,
97+
"id": "BWRfkfEpuYwPkH",
98+
"invoicing_cycle_configuration": null,
99+
"item": {
100+
"id": "KeScqBdczBZcgg",
101+
"name": "Pro Plan"
102+
},
103+
"maximum": null,
104+
"maximum_amount": null,
105+
"metadata": {},
106+
"minimum": null,
107+
"minimum_amount": null,
108+
"model_type": "unit",
109+
"name": "Pro Plan",
110+
"plan_phase_order": null,
111+
"price_type": "fixed_price",
112+
"unit_config": {
113+
"scaling_factor": null,
114+
"unit_amount": "25.00"
115+
}
116+
},
117+
"quantity": 1,
118+
"start_date": "2025-01-08T00:00:00+00:00",
119+
"sub_line_items": [],
120+
"subtotal": "25.00",
121+
"tax_amounts": []
122+
}
123+
],
124+
"maximum": null,
125+
"maximum_amount": null,
126+
"memo": null,
127+
"metadata": {},
128+
"minimum": null,
129+
"minimum_amount": null,
130+
"paid_at": "2025-01-08T08:08:54+00:00",
131+
"payment_attempts": [
132+
{
133+
"amount": "25.00",
134+
"created_at": "2025-01-08T08:06:21+00:00",
135+
"id": "PukGgsjyRtrzZM",
136+
"payment_provider": "stripe",
137+
"payment_provider_id": "pi_test_1234567890abcdef",
138+
"succeeded": true
139+
}
140+
],
141+
"payment_failed_at": null,
142+
"payment_started_at": null,
143+
"scheduled_issue_at": null,
144+
"shipping_address": null,
145+
"status": "paid",
146+
"subscription": {
147+
"id": "YPwrbnb98khpUy"
148+
},
149+
"subtotal": "25.00",
150+
"sync_failed_at": null,
151+
"total": "25.00",
152+
"voided_at": null,
153+
"will_auto_issue": false
154+
}
155+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { PostgresClient } from 'orb-sync-lib';
2+
3+
export async function deleteTestData(postgresClient: PostgresClient, table: string, ids: string[]) {
4+
if (ids.length === 0) return;
5+
const placeholders = ids.map((_, index) => `$${index + 1}`).join(',');
6+
await postgresClient.query(`DELETE FROM orb.${table} WHERE id IN (${placeholders})`, ids);
7+
}
8+
9+
export async function fetchInvoicesFromDatabase(postgresClient: PostgresClient, invoiceIds: string[]) {
10+
if (invoiceIds.length === 0) return [];
11+
12+
const placeholders = invoiceIds.map((_, index) => `$${index + 1}`).join(',');
13+
const result = await postgresClient.query(
14+
`SELECT id, invoice_number, customer_id, total, currency, status, updated_at FROM orb.invoices WHERE id IN (${placeholders})`,
15+
invoiceIds
16+
);
17+
return result.rows;
18+
}
19+
20+
export async function fetchBillingCyclesFromDatabase(postgresClient: PostgresClient, subscriptionId: string) {
21+
const result = await postgresClient.query(
22+
'SELECT id, current_billing_period_start_date, current_billing_period_end_date FROM orb.subscriptions WHERE id = $1',
23+
[subscriptionId]
24+
);
25+
return result.rows;
26+
}

0 commit comments

Comments
 (0)