Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 27 additions & 58 deletions apps/web/scripts/dev/data.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"workspace": {
"id": "ws_1KETZ919F83ZJH6A80HWEHW6E",
"id": "ws_clrei1gld0002vs9mzn93p8ik",
"name": "Acme, Inc.",
"slug": "acme",
"logo": "https://assets.dub.co/logo.png",
Expand All @@ -15,7 +15,7 @@
"usersLimit": 100,
"aiLimit": 100,
"groupsLimit": 100,
"defaultProgramId": "prog_1K2J9DRWPPJ2F1RX53N92TSGA",
"defaultProgramId": "prog_CYCu7IMAapjkRpTnr8F1azjN",
"invoicePrefix": "ACME",
"conversionEnabled": true,
"webhookEnabled": true,
Expand All @@ -24,7 +24,7 @@
},
"users": [
{
"id": "user_cludszk1h0000wmd2e0ea2b0p",
"id": "clxz1q7c7000hbqx5ckv4r82h",
"name": "Owner",
"email": "owner@dub-internal-test.com",
"emailVerified": "2026-01-21T00:00:00.000Z",
Expand Down Expand Up @@ -89,7 +89,7 @@
],
"groups": [
{
"id": "grp_1K2J9DRWPPJ2F1RX53N92TSGC",
"id": "grp_1K2E25381GVMG7HHM057TB92F",
"name": "Default Group",
"slug": "default",
"color": null,
Expand All @@ -103,95 +103,64 @@
],
"defaultLinks": [
{
"url": "https://acme.com"
},
{
"url": "https://example.com"
"url": "https://github.com/dubinc"
}
]
}
],
"program": {
"id": "prog_1K2J9DRWPPJ2F1RX53N92TSGA",
"id": "prog_CYCu7IMAapjkRpTnr8F1azjN",
"name": "Acme",
"slug": "acme",
"defaultFolderId": "fold_1K2J9DRWPPJ2F1RX53N92TSGB",
"defaultGroupId": "grp_1K2J9DRWPPJ2F1RX53N92TSGC",
"defaultGroupId": "grp_1K2E25381GVMG7HHM057TB92F",
"domain": "dub.sh",
"url": "https://acme.com",
"url": "https://acme.dub.sh/",
"termsUrl": "https://acme.com/terms",
"helpUrl": "https://acme.com/help",
"supportEmail": "support@acme.com",
"logo": "https://assets.dub.co/logo.png"
},
"partners": [
{
"id": "pn_1K2J9DRWPPJ2F1RX53N92TSGD",
"name": "Partner 1",
"email": "partner1@dub-internal-test.com",
"description": "Partner 1 description",
"id": "pn_H4TB2V5hDIjpqB7PwrxESoY3",
"name": "Steven",
"email": "steven@dub.co",
"description": "E2E Test Partner",
"country": "US",
"createdAt": "2026-01-21T00:00:00.000Z",
"user": {
"id": "user_cl8dea8g1073109m7wkwlldqj",
"name": "Partner 1",
"email": "partner1@dub-internal-test.com",
"name": "Steven",
"email": "steven@dub.co",
"emailVerified": "2026-01-21T00:00:00.000Z"
}
},
{
"id": "pn_1K2J9DRWPPJ2F1RX53N92TSGE",
"name": "Partner 2",
"email": "partner2@dub-internal-test.com",
"description": "Partner 2 description",
"id": "pn_NNG3YjwhLhA7nCZSaXeLIsWu",
"name": "Marvin",
"email": "marvin@dub-internal-test.com",
"description": "E2E Test Partner - US",
"country": "US",
"createdAt": "2026-01-21T00:00:00.000Z",
"user": {
"id": "user_cludszk1h0000wmd2e0ea2b0t",
"name": "Partner 2",
"email": "partner2@dub-internal-test.com",
"name": "Marvin",
"email": "marvin@dub-internal-test.com",
"emailVerified": "2026-01-21T00:00:00.000Z"
}
},
{
"id": "pn_1K2J9DRWPPJ2F1RX53N92TSGF",
"name": "Partner 3",
"email": "partner3@dub-internal-test.com",
"description": "Partner 3 description",
"country": "US",
"id": "pn_1K8ND11BZ4XPEX39QX3YMBGY0",
"name": "Kiran E2E",
"email": "kiran+e2e+1@dub.co",
"description": "E2E Test Partner - SG",
"country": "SG",
"createdAt": "2026-01-21T00:00:00.000Z",
"user": {
"id": "user_cludszk1h0000wmd2e0ea2b0u",
"name": "Partner 3",
"email": "partner3@dub-internal-test.com",
"emailVerified": "2026-01-21T00:00:00.000Z"
}
},
{
"id": "pn_1K2J9DRWPPJ2F1RX53N92TSGG",
"name": "Partner 4",
"email": "partner4@dub-internal-test.com",
"description": "Partner 4 description",
"country": "US",
"createdAt": "2026-01-21T00:00:00.000Z",
"user": {
"id": "user_cludszk1h0000wmd2e0ea2b0v",
"name": "Partner 4",
"email": "partner4@dub-internal-test.com",
"emailVerified": "2026-01-21T00:00:00.000Z"
}
},
{
"id": "pn_1K2J9DRWPPJ2F1RX53N92TSGH",
"name": "Partner 5",
"email": "partner5@dub-internal-test.com",
"description": "Partner 5 description",
"country": "US",
"createdAt": "2026-01-21T00:00:00.000Z",
"user": {
"id": "user_cludszk1h0000wmd2e0ea2b0w",
"name": "Partner 5",
"email": "partner5@dub-internal-test.com",
"name": "Kiran E2E",
"email": "kiran+e2e+1@dub.co",
"emailVerified": "2026-01-21T00:00:00.000Z"
}
}
Expand Down
2 changes: 0 additions & 2 deletions apps/web/tests/rewards/lead-reward.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ describe.concurrent("Lead rewards", async () => {

// Verify the commission
await verifyCommission({
http,
customerExternalId: customer.externalId,
expectedEarnings: E2E_LEAD_REWARD.modifiers[1].amountInCents,
});
Expand Down Expand Up @@ -83,7 +82,6 @@ describe.concurrent("Lead rewards", async () => {

// Verify the commission
await verifyCommission({
http,
customerExternalId: customer.externalId,
expectedEarnings: E2E_LEAD_REWARD.modifiers[0].amountInCents,
});
Expand Down
2 changes: 0 additions & 2 deletions apps/web/tests/rewards/sale-reward.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe.concurrent("Sale rewards", async () => {

// Verify the commission (10% of sale amount)
await verifyCommission({
http,
invoiceId,
expectedEarnings: saleAmount * 0.1,
});
Expand All @@ -57,7 +56,6 @@ describe.concurrent("Sale rewards", async () => {

// Verify the commission (base reward)
await verifyCommission({
http,
invoiceId,
expectedEarnings: E2E_SALE_REWARD.amountInCents,
});
Expand Down
4 changes: 0 additions & 4 deletions apps/web/tests/tracks/track-sale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,12 @@ describe.concurrent("POST /track/sale", async () => {

await Promise.all([
verifyCommission({
http,
invoiceId: regularInvoiceId,
expectedAmount: response1.data.sale?.amount!,
expectedEarnings: E2E_SALE_REWARD.amountInCents,
}),

verifyCommission({
http,
invoiceId: premiumInvoiceId,
expectedAmount: response2.data.sale?.amount!,
expectedEarnings: E2E_SALE_REWARD.modifiers[0].amountInCents!,
Expand Down Expand Up @@ -297,14 +295,12 @@ describe.concurrent("POST /track/sale", async () => {

await Promise.all([
verifyCommission({
http,
invoiceId: smallSaleInvoiceId,
expectedAmount: response1.data.sale?.amount!,
expectedEarnings: E2E_SALE_REWARD.amountInCents,
}),

verifyCommission({
http,
invoiceId: largeSaleInvoiceId,
expectedAmount: response2.data.sale?.amount!,
expectedEarnings: E2E_SALE_REWARD.modifiers[1].amountInCents!,
Expand Down
1 change: 1 addition & 0 deletions apps/web/tests/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const integrationTestEnv = z.object({
E2E_TOKEN_MEMBER: z.string().min(1),
E2E_TOKEN_OLD: z.string().min(1),
E2E_PUBLISHABLE_KEY: z.string().min(1),
E2E_DATABASE_URL: z.string().min(1),
CI: z.coerce
.string()
.default("false")
Expand Down
11 changes: 11 additions & 0 deletions apps/web/tests/utils/prisma.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PrismaClient } from "@dub/prisma/client";
import { env } from "./env";

// Dedicated Prisma client for E2E tests.
// Requires E2E_DATABASE_URL to be set explicitly.
export const prisma = new PrismaClient({
datasourceUrl: env.E2E_DATABASE_URL,
omit: {
user: { passwordHash: true },
},
});
44 changes: 15 additions & 29 deletions apps/web/tests/utils/verify-commission.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { CommissionResponse, Customer } from "@/lib/types";
import { expect } from "vitest";
import { HttpClient } from "./http";
import { prisma } from "./prisma";

interface VerifyCommissionProps {
http: HttpClient;
customerExternalId?: string;
invoiceId?: string;
expectedAmount?: number;
Expand All @@ -14,7 +12,6 @@ const POLL_INTERVAL_MS = 5000; // 5 seconds
const TIMEOUT_MS = 30000; // 30 seconds

export const verifyCommission = async ({
http,
customerExternalId,
invoiceId,
expectedAmount,
Expand All @@ -24,44 +21,33 @@ export const verifyCommission = async ({

// Resolve customer ID first if customerExternalId is given
if (customerExternalId) {
const { data: customers } = await http.get<Customer[]>({
path: "/customers",
query: { externalId: customerExternalId },
const customer = await prisma.customer.findFirst({
where: { externalId: customerExternalId },
select: { id: true },
});

expect(customers.length).toBeGreaterThan(0);
customerId = customers[0].id;
}

const query: Record<string, string> = {};

if (invoiceId) {
query.invoiceId = invoiceId;
}

if (customerId) {
query.customerId = customerId;
expect(customer).not.toBeNull();
customerId = customer!.id;
}

// Poll for commission every 5 seconds, timeout after 30 seconds
const startTime = Date.now();

while (Date.now() - startTime < TIMEOUT_MS) {
const { status, data: commissions } = await http.get<CommissionResponse[]>({
path: "/commissions",
query,
const commission = await prisma.commission.findFirst({
where: {
...(customerId && { customerId }),
...(invoiceId && { invoiceId }),
},
});

if (status === 200 && commissions.length === 1) {
const commission = commissions[0];

// Verify all expectations
if (commission) {
if (invoiceId) {
expect(commission.invoiceId).toEqual(invoiceId);
}

if (customerId) {
expect(commission.customer?.id).toEqual(customerId);
expect(commission.customerId).toEqual(customerId);
}

if (expectedAmount !== undefined) {
Expand All @@ -70,7 +56,7 @@ export const verifyCommission = async ({

expect(commission.earnings).toEqual(expectedEarnings);

return;
return commission;
}

// Wait before next poll
Expand All @@ -80,6 +66,6 @@ export const verifyCommission = async ({
// Timeout reached - fail the test
throw new Error(
`Commission not found within ${TIMEOUT_MS / 1000} seconds. ` +
`Query: ${JSON.stringify(query)}`,
`customerId: ${customerId}, invoiceId: ${invoiceId}`,
);
};
Loading
Loading