The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add tests
Kiran K1640090047e4
diff --git a/apps/web/tests/tracks/track-lead.test.ts b/apps/web/tests/tracks/track-lead.test.tsindex a1e7a83c21..905a2015c3 100644--- a/apps/web/tests/tracks/track-lead.test.ts+++ b/apps/web/tests/tracks/track-lead.test.ts@@ -1,6 +1,12 @@-import { TrackLeadResponse, TrackSaleResponse } from "@/lib/types";+import {+ CommissionResponse,+ Customer,+ TrackLeadResponse,+ TrackSaleResponse,+} from "@/lib/types";import { randomCustomer } from "tests/utils/helpers";-import { E2E_TRACK_CLICK_HEADERS } from "tests/utils/resource";+import { HttpClient } from "tests/utils/http";+import { E2E_LEAD_REWARD, E2E_TRACK_CLICK_HEADERS } from "tests/utils/resource";import { describe, expect, test } from "vitest";import { IntegrationHarness } from "../utils/integration";@@ -24,6 +30,37 @@ const expectValidLeadResponse = ({});};+const verifyCommission = async ({+ http,+ customerExternalId,+ expectedEarnings,+}: {+ http: HttpClient;+ customerExternalId: string;+ expectedEarnings: number;+}) => {+ // Find the customer first+ const { data: customer } = await http.get<Customer>({+ path: "/customers",+ query: {+ externalId: customerExternalId,+ },+ });++ // Find the commission for the customer+ const { status, data: commissions } = await http.get<CommissionResponse[]>({+ path: "/commissions",+ query: {+ customerId: customer.id,+ },+ });++ expect(status).toEqual(200);+ expect(commissions).toHaveLength(1);+ expect(commissions[0].customer?.id).toEqual(customer.id);+ expect(commissions[0].earnings).toEqual(expectedEarnings);+};+describe("POST /track/lead", async () => {const h = new IntegrationHarness();const { http } = await h.init();@@ -62,6 +99,14 @@ describe("POST /track/lead", async () => {customer: customer1,clickId: trackedClickId,});++ await new Promise((resolve) => setTimeout(resolve, 2000));++ await verifyCommission({+ http,+ customerExternalId: customer1.externalId,+ expectedEarnings: E2E_LEAD_REWARD.amount,+ });});test("duplicate track lead request with same customerExternalId", async () => {@@ -215,4 +260,44 @@ describe("POST /track/lead", async () => {clickId: trackedClickId,});});++ test("track a lead and verify the reward based on the partner.country (US)", async () => {+ const clickResponse = await http.post<{ clickId: string }>({+ path: "/track/click",+ headers: E2E_TRACK_CLICK_HEADERS,+ body: {+ domain: "getacme.link",+ key: "marvin",+ },+ });++ const trackedClickId = clickResponse.data.clickId;+ const customer = randomCustomer();++ const response = await http.post<TrackLeadResponse>({+ path: "/track/lead",+ body: {+ clickId: trackedClickId,+ customerId: customer.externalId,+ eventName: "Signup",+ customerName: customer.name,+ customerEmail: customer.email,+ customerAvatar: customer.avatar,+ },+ });++ expectValidLeadResponse({+ response,+ customer: customer,+ clickId: trackedClickId,+ });++ await new Promise((resolve) => setTimeout(resolve, 2000));++ await verifyCommission({+ http,+ customerExternalId: customer.externalId,+ expectedEarnings: E2E_LEAD_REWARD.modifiers[0].amount,+ });+ });});diff --git a/apps/web/tests/tracks/track-sale.test.ts b/apps/web/tests/tracks/track-sale.test.tsindex 9f9f3f7593..73eaf59ef4 100644--- a/apps/web/tests/tracks/track-sale.test.ts+++ b/apps/web/tests/tracks/track-sale.test.ts@@ -8,7 +8,7 @@ import {E2E_CUSTOMER_EXTERNAL_ID,E2E_CUSTOMER_EXTERNAL_ID_2,E2E_CUSTOMER_ID,- E2E_REWARD,+ E2E_SALE_REWARD,E2E_TRACK_CLICK_HEADERS,} from "tests/utils/resource";import { describe, expect, test } from "vitest";@@ -134,13 +134,13 @@ describe("POST /track/sale", async () => {http,regularInvoiceId,response1.data.sale?.amount!,- E2E_REWARD.amount,+ E2E_SALE_REWARD.amount,);await verifyCommission(http,premiumInvoiceId,response2.data.sale?.amount!,- E2E_REWARD.modifiers[0].amount,+ E2E_SALE_REWARD.modifiers[0].amount,);});@@ -315,14 +315,14 @@ describe("POST /track/sale", async () => {http,smallSaleInvoiceId,response1.data.sale?.amount!,- E2E_REWARD.amount,+ E2E_SALE_REWARD.amount,);await verifyCommission(http,largeSaleInvoiceId,response2.data.sale?.amount!,- E2E_REWARD.modifiers[1].amount,+ E2E_SALE_REWARD.modifiers[1].amount,);});});diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.tsindex e538e693f1..7b6256eb5f 100644--- a/apps/web/tests/utils/resource.ts+++ b/apps/web/tests/utils/resource.ts@@ -38,7 +38,7 @@ export const E2E_NO_ACCESS_FOLDER_LINK_ID = "link_1JP8FQE9VSVBG2G2Z6EBZWYF6"; //// Rewards specificexport const E2E_CUSTOMER_EXTERNAL_ID_2 = "cus_pqc8qRtofpu6ZqvutyNDGAU2";-export const E2E_REWARD = {+export const E2E_SALE_REWARD = {id: "rw_1JYPP77NNDG6TVPAJDKNZREQN",event: "sale",amount: 1000,@@ -69,6 +69,27 @@ export const E2E_REWARD = {},],};+export const E2E_LEAD_REWARD = {+ id: "rw_1K82ESAT4YPY0STR20GKXZ7DR",+ event: "lead",+ amount: 1000,+ modifiers: [+ {+ type: "flat",+ amount: 200,+ operator: "AND",+ conditions: [+ {+ value: "US",+ entity: "partner",+ operator: "equals_to",+ attribute: "country",+ },+ ],+ maxDuration: null,+ },+ ],+};// Discounts specificexport const E2E_CUSTOMER_WITH_DISCOUNT = {