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.

Expect generated commission descriptions in Playwright API tests.

Kiran K1fd1d85d8cf1
diff --git a/apps/web/playwright/api/commissions/helpers.ts b/apps/web/playwright/api/commissions/helpers.ts
index 3c13aa1b8e..138ecf493c 100644
--- a/apps/web/playwright/api/commissions/helpers.ts
+++ b/apps/web/playwright/api/commissions/helpers.ts
@@ -1,10 +1,40 @@
+import { buildCommissionDescription } from "@/lib/commissions/build-commission-description";
import { prisma } from "@/lib/prisma";
-import type { CommissionResponse } from "@/lib/types";
+import type { CommissionResponse, RewardConditions } from "@/lib/types";
import { expect } from "@playwright/test";
import type { ApiClient } from "../fixtures";
import { createPartner, deletePartner } from "../partners/helpers";
import { TEST_COMMISSION_REWARDS } from "../setup-test-workspace";
+function expectedCommissionDescription({
+ type,
+ earnings,
+}: {
+ type: "custom" | "lead" | "sale";
+ earnings: number;
+}): string | null {
+ if (type === "custom") {
+ return null;
+ }
+
+ const reward = TEST_COMMISSION_REWARDS[type];
+
+ return buildCommissionDescription({
+ reward: {
+ event: reward.event,
+ type: reward.type,
+ amountInCents: earnings,
+ amountInPercentage: null,
+ maxDuration: "maxDuration" in reward ? reward.maxDuration : null,
+ spendLimitAmount: null,
+ spendLimitInterval: null,
+ },
+ matchedCondition: (reward.modifiers.find(
+ (modifier) => modifier.amountInCents === earnings,
+ ) ?? null) as RewardConditions | null,
+ });
+}
+
export async function withCommissionPartner(
api: ApiClient,
program: { defaultGroupId: string },
@@ -79,16 +109,13 @@ export async function expectCommissionCreated({
expectedMetadata?: Record<string, unknown> | null;
expectedLinkId?: string;
}): Promise<string> {
- const amount =
- expectedAmount ?? (type === "lead" ? 0 : type === "sale" ? 1000 : 0);
+ const amount = expectedAmount ?? (type === "sale" ? 1000 : 0);
const earnings =
expectedEarnings ??
- (type === "lead"
- ? TEST_COMMISSION_REWARDS.lead.amountInCents
- : type === "sale"
- ? TEST_COMMISSION_REWARDS.sale.amountInCents
- : 0);
+ (type === "custom" ? 0 : TEST_COMMISSION_REWARDS[type].amountInCents);
const metadata = expectedMetadata === undefined ? null : expectedMetadata;
+ const expectedDescription =
+ description ?? expectedCommissionDescription({ type, earnings });
let commissionId: string | undefined;
@@ -135,7 +162,7 @@ export async function expectCommissionCreated({
amount,
earnings,
quantity: 1,
- description: description ?? null,
+ description: expectedDescription,
invoiceId: invoiceId ?? null,
currency: "usd",
createdAt: expectedCreatedAt
diff --git a/apps/web/playwright/api/domains/program-domain.spec.ts b/apps/web/playwright/api/domains/program-domain.spec.ts
index 94ddbf7080..447785b701 100644
--- a/apps/web/playwright/api/domains/program-domain.spec.ts
+++ b/apps/web/playwright/api/domains/program-domain.spec.ts
@@ -26,11 +26,21 @@ async function deleteDomain(api: ApiClient, slug: string | undefined) {
await api.delete(`/api/domains/${slug}`);
}
+const alreadyProgramDomainError = apiError({
+ code: "bad_request",
+ message: "This domain is already the program domain.",
+});
+
async function restoreProgramDomain(api: ApiClient) {
- const { status } = await api.post(
+ const response = await api.post(
`/api/domains/${TEST_WORKSPACE.program.domain}/program`,
);
- expect(status).toEqual(200);
+
+ if (response.status === 200) {
+ return;
+ }
+
+ expect(response).toEqual(alreadyProgramDomainError);
}
test("POST /domains/{slug}/program", async ({ api, program }) => {
@@ -76,12 +86,7 @@ test("POST /domains/{slug}/program – already the program domain", async ({
}) => {
expect(
await api.post(`/api/domains/${TEST_WORKSPACE.program.domain}/program`),
- ).toEqual(
- apiError({
- code: "bad_request",
- message: "This domain is already the program domain.",
- }),
- );
+ ).toEqual(alreadyProgramDomainError);
});
test("POST /domains/{slug}/program – archived domain", async ({ api }) => {
diff --git a/apps/web/playwright/api/embed/referrals-links.spec.ts b/apps/web/playwright/api/embed/referrals-links.spec.ts
index 24c71ce5dc..84fb1e6e46 100644
--- a/apps/web/playwright/api/embed/referrals-links.spec.ts
+++ b/apps/web/playwright/api/embed/referrals-links.spec.ts
@@ -1,6 +1,8 @@
import { prisma } from "@/lib/prisma";
+import { ReferralsEmbedLinkSchema } from "@/lib/zod/schemas/referrals-embed";
import { nanoid } from "@dub/utils";
import { expect } from "@playwright/test";
+import * as z from "zod/v4";
import { apiError } from "../../utils";
import { createBearerApiClient, test } from "../fixtures";
import {
@@ -8,14 +10,8 @@ import {
createPartner,
deletePartner,
} from "../partners/helpers";
-import { TEST_WORKSPACE } from "../setup-test-workspace";
-type EmbedLink = {
- id: string;
- domain: string;
- key: string;
- url: string;
-};
+type ReferralsEmbedLink = z.infer<typeof ReferralsEmbedLinkSchema>;
test.describe.configure({ mode: "serial" });
@@ -37,17 +33,14 @@ test("GET /embed/referrals/links", async ({ api, playwright }) => {
});
try {
- const { status, data } = await embedApi.get<EmbedLink[]>(
+ const { status, data } = await embedApi.get<ReferralsEmbedLink[]>(
"/api/embed/referrals/links",
);
expect(status).toEqual(200);
expect(data).toEqual(
expect.arrayContaining([
- expect.objectContaining({
- id: partner.links![0].id,
- domain: TEST_WORKSPACE.program.domain,
- }),
+ expect.objectContaining({ id: partner.links![0].id }),
]),
);
} finally {
@@ -79,7 +72,7 @@ test("POST /embed/referrals/links - default URL", async ({
const key = nanoid(8);
try {
- const { status, data } = await embedApi.post<EmbedLink>(
+ const { status, data } = await embedApi.post<ReferralsEmbedLink>(
"/api/embed/referrals/links",
{ key },
);
@@ -87,9 +80,9 @@ test("POST /embed/referrals/links - default URL", async ({
expect(status).toEqual(201);
expect(data).toMatchObject({
id: expect.any(String),
- domain: TEST_WORKSPACE.program.domain,
+ domain: expect.any(String),
key,
- shortLink: `https://${TEST_WORKSPACE.program.domain}/${key}`,
+ shortLink: `https://${data.domain}/${key}`,
});
} finally {
await dispose();
@@ -164,7 +157,7 @@ test("POST /embed/referrals/links - allowed additionalLinks domain", async ({
const url = `https://example.com/${nanoid()}`;
try {
- const { status, data } = await embedApi.post<EmbedLink>(
+ const { status, data } = await embedApi.post<ReferralsEmbedLink>(
"/api/embed/referrals/links",
{ key: nanoid(8), url },
);