Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix commission.created webhook tests

Steven Tey99d516dec78e
diff --git a/apps/web/lib/webhook/sample-events/commission-created.json b/apps/web/lib/webhook/sample-events/commission-created.json
index 29e3727b9b..52c9069260 100644
--- a/apps/web/lib/webhook/sample-events/commission-created.json
+++ b/apps/web/lib/webhook/sample-events/commission-created.json
@@ -1,61 +1,56 @@
{
- "id": "evt_oUxKTTaMD05AnuyqeIyz0WsCF",
- "event": "commission.created",
- "createdAt": "2025-07-09T12:10:21.848Z",
- "data": {
- "id": "cm_1JZQHG30696MDWAAP8H09AADE",
- "type": "sale",
- "amount": 50000,
- "earnings": 10000,
- "currency": "usd",
- "status": "pending",
- "invoiceId": null,
- "description": null,
- "quantity": 1,
- "createdAt": "2025-07-09T12:10:19.649Z",
- "updatedAt": "2025-07-09T12:10:20.039Z",
- "partner": {
- "id": "cm6v2l38p000zubyl5fly3i7w",
- "name": "Matthew Hayden",
- "email": "[email protected]",
- "companyName": "",
- "profileType": "individual",
- "image": null,
- "description": "I'm a content creator who works with brands to grow their business.",
- "country": "US",
- "status": "approved",
- "stripeConnectId": "acct_1Ri8yePKFVxAW5Pv",
- "paypalEmail": null,
- "payoutsEnabledAt": "2025-07-07T06:22:01.000Z",
- "invoiceSettings": {},
- "minWithdrawalAmount": 7500,
- "createdAt": "2025-07-05T05:34:41.334Z",
- "website": null,
- "websiteTxtRecord": null,
- "websiteVerifiedAt": null,
- "youtube": null,
- "youtubeVerifiedAt": null,
- "youtubeSubscriberCount": 0,
- "youtubeViewCount": 0,
- "twitter": null,
- "twitterVerifiedAt": null,
- "linkedin": null,
- "linkedinVerifiedAt": null,
- "instagram": null,
- "instagramVerifiedAt": null,
- "tiktok": null,
- "tiktokVerifiedAt": null
- },
- "customer": {
- "id": "cus_1JZQHFT1780BDFAHV5QG0K6G0",
- "externalId": "TaMD05AnuyqeI",
- "name": "David",
- "email": "[email protected]",
- "avatar": null,
- "country": "US",
- "sales": 1,
- "saleAmount": 50000,
- "createdAt": "2025-07-09T12:10:10.856Z"
- }
+ "id": "cm_1JZQHG30696MDWAAP8H09AADE",
+ "type": "sale",
+ "amount": 50000,
+ "earnings": 10000,
+ "currency": "usd",
+ "status": "pending",
+ "invoiceId": null,
+ "description": null,
+ "quantity": 1,
+ "createdAt": "2025-07-09T12:10:19.649Z",
+ "updatedAt": "2025-07-09T12:10:20.039Z",
+ "partner": {
+ "id": "cm6v2l38p000zubyl5fly3i7w",
+ "name": "Matthew Hayden",
+ "email": "[email protected]",
+ "companyName": "",
+ "profileType": "individual",
+ "image": null,
+ "description": "I'm a content creator who works with brands to grow their business.",
+ "country": "US",
+ "status": "approved",
+ "stripeConnectId": "acct_1Ri8yePKFVxAW5Pv",
+ "paypalEmail": null,
+ "payoutsEnabledAt": "2025-07-07T06:22:01.000Z",
+ "invoiceSettings": {},
+ "minWithdrawalAmount": 7500,
+ "createdAt": "2025-07-05T05:34:41.334Z",
+ "website": null,
+ "websiteTxtRecord": null,
+ "websiteVerifiedAt": null,
+ "youtube": null,
+ "youtubeVerifiedAt": null,
+ "youtubeSubscriberCount": 0,
+ "youtubeViewCount": 0,
+ "twitter": null,
+ "twitterVerifiedAt": null,
+ "linkedin": null,
+ "linkedinVerifiedAt": null,
+ "instagram": null,
+ "instagramVerifiedAt": null,
+ "tiktok": null,
+ "tiktokVerifiedAt": null
+ },
+ "customer": {
+ "id": "cus_1JZQHFT1780BDFAHV5QG0K6G0",
+ "externalId": "TaMD05AnuyqeI",
+ "name": "David",
+ "email": "[email protected]",
+ "avatar": null,
+ "country": "US",
+ "sales": 1,
+ "saleAmount": 50000,
+ "createdAt": "2025-07-09T12:10:10.856Z"
}
}
diff --git a/apps/web/lib/zod/schemas/commissions.ts b/apps/web/lib/zod/schemas/commissions.ts
index 4cd3b970f5..346501a7d0 100644
--- a/apps/web/lib/zod/schemas/commissions.ts
+++ b/apps/web/lib/zod/schemas/commissions.ts
@@ -4,6 +4,7 @@ import { z } from "zod";
import { CustomerSchema } from "./customers";
import { getPaginationQuerySchema } from "./misc";
import { PartnerSchema } from "./partners";
+import { ProgramEnrollmentSchema } from "./programs";
import { parseDateSchema } from "./utils";
export const CommissionSchema = z.object({
@@ -20,7 +21,7 @@ export const CommissionSchema = z.object({
quantity: z.number(),
userId: z
.string()
- .nullable()
+ .nullish()
.describe("The user who created the manual commission."),
createdAt: z.date(),
updatedAt: z.date(),
@@ -29,7 +30,11 @@ export const CommissionSchema = z.object({
// Represents the commission object used in webhook and API responses (/api/commissions/**)
export const CommissionEnrichedSchema = CommissionSchema.merge(
z.object({
- partner: PartnerSchema,
+ partner: PartnerSchema.merge(
+ ProgramEnrollmentSchema.pick({
+ status: true,
+ }),
+ ),
customer: CustomerSchema.nullish(), // customer can be null for click-based / custom commissions
}),
);
diff --git a/apps/web/tests/webhooks/index.test.ts b/apps/web/tests/webhooks/index.test.ts
index c40465f5d6..1ae9487c18 100644
--- a/apps/web/tests/webhooks/index.test.ts
+++ b/apps/web/tests/webhooks/index.test.ts
@@ -44,8 +44,14 @@ const enrolledPartnerSchemaExtended = EnrolledPartnerSchema.extend({
const commissionWebhookEventSchemaExtended = CommissionEnrichedSchema.extend({
createdAt: z.string().transform((str) => new Date(str)),
updatedAt: z.string().transform((str) => new Date(str)),
- customer: customerSchemaExtended.nullish(),
- partner: enrolledPartnerSchemaExtended,
+ partner: CommissionEnrichedSchema.shape.partner.extend({
+ payoutsEnabledAt: z
+ .string()
+ .transform((str) => (str ? new Date(str) : null))
+ .nullable(),
+ createdAt: z.string().transform((str) => new Date(str)),
+ }),
+ customer: customerSchemaExtended,
});
const eventSchemas: Record<WebhookTrigger, z.ZodSchema> = {