The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix Fraud E2E tests (#3595)
Steven Teycd9957207763
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/program-fraud-settings-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/program-fraud-settings-sheet.tsxindex 2b4c90d653..ace802723a 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/program-fraud-settings-sheet.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/fraud/program-fraud-settings-sheet.tsx@@ -184,8 +184,6 @@ function ProgramFraudSettingsSheetContent({<div className="h-full overflow-y-auto p-4 sm:p-6"><div className="space-y-4">- <FraudPaidTrafficSettings isConfigLoading={isLoading} />- <FraudReferralSourceSettings isConfigLoading={isLoading} />{TOGGLE_ONLY_RULES.map((rule) => (<FraudRuleToggleSettingskey={rule.type}@@ -195,6 +193,8 @@ function ProgramFraudSettingsSheetContent({isConfigLoading={isLoading}/>))}+ <FraudPaidTrafficSettings isConfigLoading={isLoading} />+ <FraudReferralSourceSettings isConfigLoading={isLoading} /></div></div>diff --git a/apps/web/lib/api/fraud/constants.ts b/apps/web/lib/api/fraud/constants.tsindex 439a7aed6a..a10433b5ed 100644--- a/apps/web/lib/api/fraud/constants.ts+++ b/apps/web/lib/api/fraud/constants.ts@@ -18,19 +18,21 @@ export const FRAUD_RULES: FraudRuleInfo[] = [scope: "conversionEvent",configurable: true,},++ // Referral source rules{- type: "referralSourceBanned",- name: "Banned referral source",+ type: "paidTrafficDetected",+ name: "Paid traffic",description:- "A conversion, event, or click was made on a banned referral domain.",+ "A conversion, event, or click was made from paid advertising traffic.",scope: "conversionEvent",configurable: true,},{- type: "paidTrafficDetected",- name: "Paid traffic",+ type: "referralSourceBanned",+ name: "Banned referral source",description:- "A conversion, event, or click was made from paid advertising traffic.",+ "A conversion, event, or click was made on a banned referral domain.",scope: "conversionEvent",configurable: true,},diff --git a/apps/web/lib/is-generic-email.ts b/apps/web/lib/is-generic-email.tsindex 8b0971487c..917787c3dc 100644--- a/apps/web/lib/is-generic-email.ts+++ b/apps/web/lib/is-generic-email.ts@@ -31,6 +31,7 @@ export const GENERIC_EMAIL_DOMAINS = ["tutanota.com","tuta.com","privaterelay.appleid.com",+ "example.com",];export const isGenericEmail = (email: string) => {diff --git a/apps/web/tests/embed-tokens/referrals.test.ts b/apps/web/tests/embed-tokens/referrals.test.tsindex 761636682f..fa6cf8aee0 100644--- a/apps/web/tests/embed-tokens/referrals.test.ts+++ b/apps/web/tests/embed-tokens/referrals.test.ts@@ -1,6 +1,6 @@import { generateRandomName } from "@/lib/names";import { describe, expect, test } from "vitest";-import { randomEmail, randomId } from "../utils/helpers";+import { randomId, randomPartnerEmail } from "../utils/helpers";import { IntegrationHarness } from "../utils/integration";import { E2E_PARTNER } from "../utils/resource";@@ -30,7 +30,7 @@ describe.sequential("POST /api/tokens/embed/referrals", async () => {test("with new partner props (creates new partner)", async () => {const partner = {name: generateRandomName(),- email: randomEmail(),+ email: randomPartnerEmail(),description: "A test partner for embed token",country: "US",image: "https://api.dicebear.com/9.x/micah/png?seed=test",@@ -66,7 +66,7 @@ describe.sequential("POST /api/tokens/embed/referrals", async () => {test("with minimal partner props", async () => {const partner = {- email: randomEmail(),+ email: randomPartnerEmail(),};const { data, status } = await http.post({diff --git a/apps/web/tests/fraud/index.test.ts b/apps/web/tests/fraud/index.test.tsindex e179e557cf..5c77358350 100644--- a/apps/web/tests/fraud/index.test.ts+++ b/apps/web/tests/fraud/index.test.ts@@ -102,6 +102,41 @@ describe.concurrent("/fraud/**", async () => {});});+ test("FraudRuleType = customerEmailMatch (historical domain match)", async () => {+ const clickLink = E2E_FRAUD_PARTNER.links.customerEmailMatch;++ const clickResponse = await http.post<{ clickId: string }>({+ path: "/track/click",+ headers: { ...E2E_TRACK_CLICK_HEADERS },+ body: { domain: clickLink.domain, key: clickLink.key },+ });++ const trackedClickId = clickResponse.data.clickId;++ const customer = randomCustomer({ emailDomain: "google.com" });++ await http.post<TrackLeadResponse>({+ path: "/track/lead",+ body: {+ eventName: "Signup",+ clickId: trackedClickId,+ customerId: customer.externalId,+ customerName: customer.name,+ customerEmail: customer.email,+ customerAvatar: customer.avatar,+ },+ });++ await verifyFraudEvent({+ http,+ customer,+ ruleType: "customerEmailMatch",+ metadata: {+ matchType: CustomerEmailMatchType.HISTORICAL_DOMAIN_MATCH,+ },+ });+ });+test("FraudRuleType = customerEmailSuspiciousDomain", async () => {const clickLink = E2E_FRAUD_PARTNER.links.customerEmailSuspiciousDomain;diff --git a/apps/web/tests/partners/ban-partner.test.ts b/apps/web/tests/partners/ban-partner.test.tsindex 65f03aa2cb..30c17bcfd9 100644--- a/apps/web/tests/partners/ban-partner.test.ts+++ b/apps/web/tests/partners/ban-partner.test.ts@@ -2,7 +2,7 @@ import { generateRandomName } from "@/lib/names";import { EnrolledPartnerSchema as EnrolledPartnerSchemaDate } from "@/lib/zod/schemas/partners";import { describe, expect, test } from "vitest";import { fetchPartner } from "../utils/fetch-partner";-import { randomEmail, randomId } from "../utils/helpers";+import { randomId, randomPartnerEmail } from "../utils/helpers";import { IntegrationHarness } from "../utils/integration";import { E2E_PARTNER_GROUP } from "../utils/resource";import { normalizedPartnerDateFields } from "./resource";@@ -18,7 +18,7 @@ describe.sequential("POST /partners/ban", async () => {test("ban partner by partnerId", async () => {const partner = {name: generateRandomName(),- email: randomEmail(),+ email: randomPartnerEmail(),groupId: E2E_PARTNER_GROUP.id,};@@ -56,7 +56,7 @@ describe.sequential("POST /partners/ban", async () => {const partner = {name: generateRandomName(),- email: randomEmail(),+ email: randomPartnerEmail(),tenantId,groupId: E2E_PARTNER_GROUP.id,};diff --git a/apps/web/tests/partners/create-partner.test.ts b/apps/web/tests/partners/create-partner.test.tsindex bb9c5981a6..b86791a874 100644--- a/apps/web/tests/partners/create-partner.test.ts+++ b/apps/web/tests/partners/create-partner.test.ts@@ -3,7 +3,7 @@ import { EnrolledPartnerSchema as EnrolledPartnerSchemaDate } from "@/lib/zod/scimport { Link, Partner } from "@dub/prisma/client";import { R2_URL } from "@dub/utils";import { describe, expect, test } from "vitest";-import { randomEmail, randomId } from "../utils/helpers";+import { randomId, randomPartnerEmail } from "../utils/helpers";import { IntegrationHarness } from "../utils/integration";import { E2E_PARTNER_GROUP, E2E_PROGRAM } from "../utils/resource";import { normalizedPartnerDateFields } from "./resource";@@ -19,7 +19,7 @@ describe.sequential("POST /partners", async () => {test("with required fields only", async () => {const partner = {name: generateRandomName(),- email: randomEmail(),+ email: randomPartnerEmail(),groupId: E2E_PARTNER_GROUP.id,};@@ -37,7 +37,7 @@ describe.sequential("POST /partners", async () => {test("with all fields", async () => {const partner = {name: generateRandomName(),- email: randomEmail(),+ email: randomPartnerEmail(),tenantId: randomId(),groupId: E2E_PARTNER_GROUP.id,description: "A description of the partner",@@ -77,7 +77,7 @@ describe.sequential("POST /partners", async () => {const partner = {name: generateRandomName(),- email: randomEmail(),+ email: randomPartnerEmail(),groupId: E2E_PARTNER_GROUP.id,};@@ -110,7 +110,7 @@ describe.sequential("POST /partners", async () => {});test("upsert behavior - update existing partner with tenantId", async () => {- const email = randomEmail();+ const email = randomPartnerEmail();// First, create a partner with email and no tenantIdconst initialPartner = {diff --git a/apps/web/tests/partners/deactivate-partner.test.ts b/apps/web/tests/partners/deactivate-partner.test.tsindex 39a1dae717..18e3ae5211 100644--- a/apps/web/tests/partners/deactivate-partner.test.ts+++ b/apps/web/tests/partners/deactivate-partner.test.ts@@ -2,7 +2,7 @@ import { generateRandomName } from "@/lib/names";import { EnrolledPartnerSchema as EnrolledPartnerSchemaDate } from "@/lib/zod/schemas/partners";import { describe, expect, test } from "vitest";import { fetchPartner } from "../utils/fetch-partner";-import { randomEmail, randomId } from "../utils/helpers";+import { randomId, randomPartnerEmail } from "../utils/helpers";import { IntegrationHarness } from "../utils/integration";import { E2E_PARTNER_GROUP } from "../utils/resource";import { normalizedPartnerDateFields } from "./resource";@@ -18,7 +18,7 @@ describe.concurrent("POST /partners/deactivate", async () => {test("deactivate partner by partnerId", async () => {const partner = {name: generateRandomName(),- email: randomEmail(),+ email: randomPartnerEmail(),groupId: E2E_PARTNER_GROUP.id,};@@ -55,7 +55,7 @@ describe.concurrent("POST /partners/deactivate", async () => {const partner = {name: generateRandomName(),- email: randomEmail(),+ email: randomPartnerEmail(),tenantId,groupId: E2E_PARTNER_GROUP.id,};diff --git a/apps/web/tests/utils/helpers.ts b/apps/web/tests/utils/helpers.tsindex 9310cde732..695bf72051 100644--- a/apps/web/tests/utils/helpers.ts+++ b/apps/web/tests/utils/helpers.ts@@ -23,7 +23,7 @@ export const randomTagName = (length?: number) => {return `e2e-${randomId(length)}`;};-export const randomEmail = ({+export const randomPartnerEmail = ({domain = "dub-internal-test.com",}: {domain?: string;diff --git a/apps/web/tests/workflows/award-bounty-workflow.test.ts b/apps/web/tests/workflows/award-bounty-workflow.test.tsindex 30cf2b8b57..1c36f62e09 100644--- a/apps/web/tests/workflows/award-bounty-workflow.test.ts+++ b/apps/web/tests/workflows/award-bounty-workflow.test.ts@@ -2,7 +2,7 @@ import { EnrolledPartnerProps } from "@/lib/types";import { Bounty } from "@dub/prisma/client";import { E2E_PARTNER_GROUP } from "tests/utils/resource";import { describe, expect, onTestFinished, test } from "vitest";-import { randomEmail } from "../utils/helpers";+import { randomPartnerEmail } from "../utils/helpers";import { IntegrationHarness } from "../utils/integration";import { deleteBountyAndSubmissions } from "./utils/delete-bounty-and-submissions";import { trackE2ELead } from "./utils/track-e2e-lead";@@ -49,7 +49,7 @@ describe.sequential("Workflow - AwardBounty", async () => {path: "/partners",body: {name: "E2E Test Partner - Goal",- email: randomEmail(),+ email: randomPartnerEmail(),groupId: E2E_PARTNER_GROUP.id,},});@@ -110,7 +110,7 @@ describe.sequential("Workflow - AwardBounty", async () => {path: "/partners",body: {name: "E2E Test Partner - Not Reached",- email: randomEmail(),+ email: randomPartnerEmail(),groupId: E2E_PARTNER_GROUP.id,},});@@ -184,7 +184,7 @@ describe.sequential("Workflow - AwardBounty", async () => {path: "/partners",body: {name: "E2E Test Partner - Disabled",- email: randomEmail(),+ email: randomPartnerEmail(),groupId: E2E_PARTNER_GROUP.id,},});@@ -243,7 +243,7 @@ describe.sequential("Workflow - AwardBounty", async () => {path: "/partners",body: {name: "E2E Test Partner - No Dup",- email: randomEmail(),+ email: randomPartnerEmail(),groupId: E2E_PARTNER_GROUP.id,},});diff --git a/apps/web/tests/workflows/move-group-workflow.test.ts b/apps/web/tests/workflows/move-group-workflow.test.tsindex 1a49ed0001..76713061b9 100644--- a/apps/web/tests/workflows/move-group-workflow.test.ts+++ b/apps/web/tests/workflows/move-group-workflow.test.ts@@ -4,7 +4,7 @@ import { PartnerGroup } from "@dub/prisma/client";import { randomValue } from "@dub/utils";import { E2E_PARTNER } from "tests/utils/resource";import { describe, expect, onTestFinished, test } from "vitest";-import { randomEmail } from "../utils/helpers";+import { randomPartnerEmail } from "../utils/helpers";import { IntegrationHarness } from "../utils/integration";import { trackE2ELead } from "./utils/track-e2e-lead";import { verifyPartnerGroupMove } from "./utils/verify-partner-group-move";@@ -200,7 +200,7 @@ describe.sequential("Workflow - MoveGroup", async () => {path: "/partners",body: {name: "E2E Test Partner - Disabled Move",- email: randomEmail(),+ email: randomPartnerEmail(),groupId: sourceGroup.id,},});@@ -268,7 +268,7 @@ describe.sequential("Workflow - MoveGroup", async () => {path: "/partners",body: {name: "E2E Test Partner - Not Met",- email: randomEmail(),+ email: randomPartnerEmail(),groupId: sourceGroup.id,},});@@ -339,7 +339,7 @@ describe.sequential("Workflow - MoveGroup", async () => {path: "/partners",body: {name: "E2E Test Partner - Move Execution",- email: randomEmail(),+ email: randomPartnerEmail(),groupId: sourceGroup.id,},});@@ -410,7 +410,7 @@ describe.sequential("Workflow - MoveGroup", async () => {path: "/partners",body: {name: "E2E Test Partner - No Dup Move",- email: randomEmail(),+ email: randomPartnerEmail(),groupId: sourceGroup.id,},});diff --git a/apps/web/tests/workflows/send-campaign-workflow.test.ts b/apps/web/tests/workflows/send-campaign-workflow.test.tsindex 4c1053837b..8dcc53528f 100644--- a/apps/web/tests/workflows/send-campaign-workflow.test.ts+++ b/apps/web/tests/workflows/send-campaign-workflow.test.ts@@ -2,7 +2,7 @@ import { EnrolledPartnerProps } from "@/lib/types";import { Campaign } from "@dub/prisma/client";import { subHours } from "date-fns";import { describe, expect, onTestFinished, test } from "vitest";-import { randomEmail } from "../utils/helpers";+import { randomPartnerEmail } from "../utils/helpers";import { IntegrationHarness } from "../utils/integration";import { E2E_USER_ID } from "../utils/resource";@@ -319,7 +319,7 @@ describe.sequential("Workflow - SendCampaign", async () => {path: "/partners",body: {name: "E2E Test Partner - Campaign Send",- email: randomEmail(),+ email: randomPartnerEmail(),},});@@ -396,7 +396,7 @@ describe.sequential("Workflow - SendCampaign", async () => {path: "/partners",body: {name: "E2E Test Partner - No Match",- email: randomEmail(),+ email: randomPartnerEmail(),},});@@ -474,7 +474,7 @@ describe.sequential("Workflow - SendCampaign", async () => {path: "/partners",body: {name: "E2E Test Partner - No Dup Campaign",- email: randomEmail(),+ email: randomPartnerEmail(),},});