Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhooks e2e #1893

Merged
merged 11 commits into from
Jan 15, 2025
Merged
3 changes: 3 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ jobs:
E2E_USER_ID: ${{ secrets.E2E_USER_ID }}
E2E_USER_ID_OLD: ${{ secrets.E2E_USER_ID_OLD }}
E2E_WORKSPACE_ID: ${{ secrets.E2E_WORKSPACE_ID }}
QSTASH_TOKEN: ${{ secrets.QSTASH_TOKEN }}
QSTASH_CURRENT_SIGNING_KEY: ${{ secrets.QSTASH_CURRENT_SIGNING_KEY }}
NEXT_PUBLIC_NGROK_URL: ${{ github.event.deployment_status.environment_url }}
run: pnpm test
1 change: 1 addition & 0 deletions apps/web/lib/webhook/qstash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const publishWebhookEventToQStash = async ({
},
callback: callbackUrl.href,
failureCallback: callbackUrl.href,
...(process.env.NODE_ENV === "test" && { delay: 2 }),
});

if (!response.messageId) {
Expand Down
68 changes: 38 additions & 30 deletions apps/web/lib/webhook/sample-events/lead-created.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,72 @@
{
"eventName": "Sign up",
"eventName": "Signup",
"customer": {
"id": "oU5P0SqI8fpwx5bxw1",
"name": "John",
"email": "[email protected]",
"avatar": "https://example.com/john.jpeg"
"id": "cus_Ql3PvCTbPXBpp6vn7x5oHb5G",
"externalId": "cus_BH6tDUWc9n0Y2pf55tVbk1hc",
"name": "Tiny Beige Badger",
"email": "[email protected]",
"avatar": "https://api.dicebear.com/9.x/notionists/png?seed=cus_BH6tDUWc9n0Y2pf55tVbk1hc",
"createdAt": "2025-01-14T04:49:23.385Z"
},
"click": {
"id": "d0UtZqE0BZuBPrJS",
"id": "GWGrkftJdYlZD2mq",
"url": "https://github.com/dubinc/dub",
"ip": "63.141.57.109",
"continent": "NA",
"country": "US",
"city": "San Francisco",
"city": "San Jose",
"region": "sfo1",
"continent": "NA",
"device": "Desktop",
"browser": "Chrome",
"os": "Mac OS",
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
"bot": false,
"referer": "(direct)",
"refererUrl": "(direct)",
"qr": false,
"referer": "(direct)"
"ip": "185.211.32.242"
},
"link": {
"id": "cm0faqkyn0001txvfwjfeq7gl",
"id": "cm0lcuvtz000xcutmqw4a7wi3",
"domain": "dub.sh",
"key": "79ys3WA",
"externalId": null,
"key": "track-test",
"url": "https://github.com/dubinc/dub",
"trackConversion": true,
"externalId": null,
"tenantId": null,
"archived": false,
"expiresAt": null,
"expiresAt": "1970-01-01T00:00:00.000Z",
"expiredUrl": null,
"password": null,
"proxy": false,
"title": null,
"description": null,
"image": null,
"title": "GitHub - dubinc/dub: Open-source link management infrastructure. Loved by modern marketing teams like Vercel, Raycast...",
"description": "Open-source link management infrastructure. Loved by modern marketing teams like Vercel, Raycast, and Perplexity. - dubinc/dub",
"image": "https://repository-images.githubusercontent.com/529708137/419e9be4-a9d1-4c85-9f83-47a78ad92583",
"video": null,
"rewrite": false,
"doIndex": false,
"ios": null,
"android": null,
"geo": null,
"publicStats": false,
"tagId": null,
"tags": [],
"webhookIds": [],
"comments": null,
"shortLink": "https://dub.sh/79ys3WA",
"qrCode": "https://api.dub.co/qr?url=https://dub.sh/79ys3WA?qr=1",
"shortLink": "https://dub.sh/track-test",
"qrCode": "https://api.dub.co/qr?url=https://dub.sh/track-test?qr=1",
"utm_source": null,
"utm_medium": null,
"utm_campaign": null,
"utm_term": null,
"utm_content": null,
"userId": "cm022rkcw0000ikt14mscg9sg",
"workspaceId": "ws_cm022sis60003ikt1syy7kfhl",
"clicks": 10,
"lastClicked": "2024-08-30T07:45:09.000Z",
"leads": 5,
"sales": 0,
"saleAmount": 0,
"createdAt": "2024-08-29T13:03:59.098Z",
"updatedAt": "2024-08-30T09:53:49.505Z"
"userId": "cludszk1h0000wmd2e0ea2b0p",
"workspaceId": "ws_clrei1gld0002vs9mzn93p8ik",
"clicks": 882,
"lastClicked": "2025-01-14T04:49:10.000Z",
"leads": 3632,
"sales": 2811,
"saleAmount": 290300,
"createdAt": "2024-09-02T18:49:56.136Z",
"updatedAt": "2025-01-14T04:49:23.740Z",
"projectId": "clrei1gld0002vs9mzn93p8ik",
"programId": "prog_CYCu7IMAapjkRpTnr8F1azjN"
}
}
56 changes: 29 additions & 27 deletions apps/web/lib/webhook/sample-events/link-clicked.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
{
"click": {
"id": "CvQhPEXvqRYG4mqL",
"url": "https://github.com/dubinc",
"continent": "AS",
"country": "IN",
"city": "Thalassery",
"id": "yNrYm0F6r1KMnq6N",
"url": "https://github.com/dubinc/dub",
"country": "US",
"city": "San Jose",
"region": "CA",
"continent": "NA",
"device": "Desktop",
"browser": "Chrome",
"os": "Mac OS",
"browser": "Unknown",
"os": "Unknown",
"referer": "(direct)",
"refererUrl": "(direct)",
"qr": false,
"ip": "103.181.40.30"
"ip": "52.234.41.119"
},
"link": {
"id": "cm2a01bzt0001jc3nzycksls1",
"id": "cm0lcuvtz000xcutmqw4a7wi3",
"domain": "dub.sh",
"key": "qviSU44",
"url": "https://github.com/dubinc",
"trackConversion": false,
"key": "track-test",
"url": "https://github.com/dubinc/dub",
"trackConversion": true,
"externalId": null,
"identifier": null,
"tenantId": null,
"archived": false,
"expiresAt": "1970-01-01T00:00:00.000Z",
"expiredUrl": null,
"password": null,
"proxy": false,
"title": null,
"description": null,
"image": null,
"title": "GitHub - dubinc/dub: Open-source link management infrastructure. Loved by modern marketing teams like Vercel, Raycast...",
"description": "Open-source link management infrastructure. Loved by modern marketing teams like Vercel, Raycast, and Perplexity. - dubinc/dub",
"image": "https://repository-images.githubusercontent.com/529708137/419e9be4-a9d1-4c85-9f83-47a78ad92583",
"video": null,
"rewrite": false,
"doIndex": false,
Expand All @@ -40,22 +41,23 @@
"tags": [],
"webhookIds": [],
"comments": null,
"shortLink": "https://dub.sh/qviSU44",
"qrCode": "https://api.dub.co/qr?url=https://dub.sh/qviSU44?qr=1",
"shortLink": "https://dub.sh/track-test",
"qrCode": "https://api.dub.co/qr?url=https://dub.sh/track-test?qr=1",
"utm_source": null,
"utm_medium": null,
"utm_campaign": null,
"utm_term": null,
"utm_content": null,
"userId": "clxz1q7c7000hbqx5ckv4r82h",
"userId": "cludszk1h0000wmd2e0ea2b0p",
"workspaceId": "ws_clrei1gld0002vs9mzn93p8ik",
"clicks": 1,
"lastClicked": "2024-10-15T06:35:33.000Z",
"leads": 0,
"sales": 0,
"saleAmount": 0,
"createdAt": "2024-10-15T05:24:58.744Z",
"updatedAt": "2024-10-15T05:24:58.744Z",
"projectId": "clrei1gld0002vs9mzn93p8ik"
"clicks": 882,
"lastClicked": "2025-01-14T04:49:10.000Z",
"leads": 3631,
"sales": 2811,
"saleAmount": 290300,
"createdAt": "2024-09-02T18:49:56.136Z",
"updatedAt": "2025-01-13T22:46:22.152Z",
"projectId": "clrei1gld0002vs9mzn93p8ik",
"programId": "prog_CYCu7IMAapjkRpTnr8F1azjN"
}
}
3 changes: 3 additions & 0 deletions apps/web/lib/webhook/sample-events/link-created.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"domain": "dub.sh",
"key": "sOvvXDT",
"externalId": null,
"tenantId": null,
"url": "https://github.com/stack-auth/stack",
"trackConversion": false,
"archived": false,
Expand All @@ -22,6 +23,8 @@
"publicStats": false,
"tagId": null,
"tags": [],
"webhookIds": [],
"programId": null,
"comments": null,
"shortLink": "https://dub.sh/sOvvXDT",
"qrCode": "https://api.dub.co/qr?url=https://dub.sh/sOvvXDT?qr=1",
Expand Down
3 changes: 3 additions & 0 deletions apps/web/lib/webhook/sample-events/link-deleted.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"domain": "dub.sh",
"key": "sOvvXDT",
"externalId": null,
"tenantId": null,
"url": "https://github.com/stack-auth/stack",
"trackConversion": false,
"archived": false,
Expand All @@ -22,6 +23,8 @@
"publicStats": false,
"tagId": null,
"tags": [],
"webhookIds": [],
"programId": null,
"comments": null,
"shortLink": "https://dub.sh/sOvvXDT",
"qrCode": "https://api.dub.co/qr?url=https://dub.sh/sOvvXDT?qr=1",
Expand Down
3 changes: 3 additions & 0 deletions apps/web/lib/webhook/sample-events/link-updated.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"domain": "dub.sh",
"key": "sOvvXDT",
"externalId": null,
"tenantId": null,
"url": "https://github.com/stack-auth/stack",
"trackConversion": false,
"archived": false,
Expand All @@ -22,6 +23,8 @@
"publicStats": false,
"tagId": null,
"tags": [],
"webhookIds": [],
"programId": null,
"comments": null,
"shortLink": "https://dub.sh/sOvvXDT",
"qrCode": "https://api.dub.co/qr?url=https://dub.sh/sOvvXDT?qr=1",
Expand Down
72 changes: 40 additions & 32 deletions apps/web/lib/webhook/sample-events/sale-created.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,78 @@
{
"eventName": "Purchased",
"eventName": "Subscription",
"customer": {
"id": "cm0gjdvr20001dkbha2n9gt2b",
"name": "John",
"email": "[email protected]",
"avatar": "https://example.com/john.jpeg"
"id": "cm25onzuv0001s1bbxchrc0ae",
"externalId": "cus_jTrfVKYN3Buc3F80JoqBiY0g",
"name": "Rural Red Goldfish",
"email": "[email protected]",
"avatar": "https://api.dicebear.com/9.x/notionists/png?seed=cus_jTrfVKYN3Buc3F80JoqBiY0g",
"createdAt": "2024-10-12T04:55:36.007Z"
},
"click": {
"id": "d0UtZqE0BZuBPrJS",
"id": "GWGrkftJdYlZD2mq",
"url": "https://github.com/dubinc/dub",
"ip": "63.141.57.109",
"continent": "NA",
"country": "US",
"city": "San Francisco",
"city": "San Jose",
"region": "sfo1",
"continent": "NA",
"device": "Desktop",
"browser": "Chrome",
"os": "Mac OS",
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
"bot": false,
"referer": "(direct)",
"refererUrl": "(direct)",
"qr": false,
"referer": "(direct)"
"ip": "185.211.32.242"
},
"link": {
"id": "cm0faqkyn0001txvfwjfeq7gl",
"id": "cm0lcuvtz000xcutmqw4a7wi3",
"domain": "dub.sh",
"key": "79ys3WA",
"externalId": null,
"key": "track-test",
"url": "https://github.com/dubinc/dub",
"trackConversion": true,
"externalId": null,
"tenantId": null,
"archived": false,
"expiresAt": null,
"expiresAt": "1970-01-01T00:00:00.000Z",
"expiredUrl": null,
"password": null,
"proxy": false,
"title": null,
"description": null,
"image": null,
"title": "GitHub - dubinc/dub: Open-source link management infrastructure. Loved by modern marketing teams like Vercel, Raycast...",
"description": "Open-source link management infrastructure. Loved by modern marketing teams like Vercel, Raycast, and Perplexity. - dubinc/dub",
"image": "https://repository-images.githubusercontent.com/529708137/419e9be4-a9d1-4c85-9f83-47a78ad92583",
"video": null,
"rewrite": false,
"doIndex": false,
"ios": null,
"android": null,
"geo": null,
"publicStats": false,
"tagId": null,
"tags": [],
"webhookIds": [],
"comments": null,
"shortLink": "https://dub.sh/79ys3WA",
"qrCode": "https://api.dub.co/qr?url=https://dub.sh/79ys3WA?qr=1",
"shortLink": "https://dub.sh/track-test",
"qrCode": "https://api.dub.co/qr?url=https://dub.sh/track-test?qr=1",
"utm_source": null,
"utm_medium": null,
"utm_campaign": null,
"utm_term": null,
"utm_content": null,
"userId": "cm022rkcw0000ikt14mscg9sg",
"workspaceId": "ws_cm022sis60003ikt1syy7kfhl",
"clicks": 10,
"lastClicked": "2024-08-30T07:45:09.000Z",
"leads": 5,
"sales": 1,
"saleAmount": 20000,
"createdAt": "2024-08-29T13:03:59.098Z",
"updatedAt": "2024-08-30T09:57:50.891Z"
"userId": "cludszk1h0000wmd2e0ea2b0p",
"workspaceId": "ws_clrei1gld0002vs9mzn93p8ik",
"clicks": 882,
"lastClicked": "2025-01-14T04:49:10.000Z",
"leads": 3632,
"sales": 2812,
"saleAmount": 290400,
"createdAt": "2024-09-02T18:49:56.136Z",
"updatedAt": "2025-01-14T04:49:30.459Z",
"projectId": "clrei1gld0002vs9mzn93p8ik",
"programId": "prog_CYCu7IMAapjkRpTnr8F1azjN"
},
"sale": {
"amount": 4500,
"amount": 100,
"currency": "usd",
"paymentProcessor": "stripe",
"invoiceId": null
"invoiceId": "INV_AUTi534JCiBUVdYmevCSYQ9G"
}
}
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"typescript": "^5.4.4",
"vite": "5.2.9",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "1.5.0"
"vitest": "2.1.8"
},
"browser": {
"crypto": false
Expand Down
7 changes: 7 additions & 0 deletions apps/web/tests/setupTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import crypto from "node:crypto";

Object.defineProperty(globalThis, "crypto", {
value: crypto,
writable: false, // Ensure it's not writable
configurable: true, // Allow reconfiguration if needed
});
Loading
Loading