From 09d3505e6bbb14f16ce3ec3016dbd0a22891340f Mon Sep 17 00:00:00 2001 From: Kiran K Date: Tue, 28 Oct 2025 14:24:32 +0530 Subject: [PATCH 1/6] Create index.test.ts --- apps/web/tests/rewards/index.test.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 apps/web/tests/rewards/index.test.ts diff --git a/apps/web/tests/rewards/index.test.ts b/apps/web/tests/rewards/index.test.ts new file mode 100644 index 00000000000..e69de29bb2d From a4ada1f78ad2a67e8323ffdf2b37e085ba35367a Mon Sep 17 00:00:00 2001 From: Kiran K Date: Tue, 28 Oct 2025 16:29:59 +0530 Subject: [PATCH 2/6] Add E2E tests for partner country-based rewards --- apps/web/tests/rewards/index.test.ts | 129 ++++++++++++++++++++++ apps/web/tests/tracks/track-lead.test.ts | 42 +------ apps/web/tests/utils/resource.ts | 46 +++++++- apps/web/tests/utils/verify-commission.ts | 38 +++++++ 4 files changed, 213 insertions(+), 42 deletions(-) create mode 100644 apps/web/tests/utils/verify-commission.ts diff --git a/apps/web/tests/rewards/index.test.ts b/apps/web/tests/rewards/index.test.ts index e69de29bb2d..9f8a0f24e1a 100644 --- a/apps/web/tests/rewards/index.test.ts +++ b/apps/web/tests/rewards/index.test.ts @@ -0,0 +1,129 @@ +import { TrackLeadResponse } from "@/lib/types"; +import { randomCustomer } from "tests/utils/helpers"; +import { + E2E_LEAD_REWARD, + E2E_PARTNERS, + E2E_TRACK_CLICK_HEADERS, +} from "tests/utils/resource"; +import { verifyCommission } from "tests/utils/verify-commission"; +import { describe, expect, test } from "vitest"; +import { IntegrationHarness } from "../utils/integration"; + +describe.concurrent("Rewards based on partner's country", async () => { + const h = new IntegrationHarness(); + const { http } = await h.init(); + + test("when {Partner} {Country} is {US}", async () => { + // Track the click + const clickResponse = await http.post<{ clickId: string }>({ + path: "/track/click", + headers: E2E_TRACK_CLICK_HEADERS, + body: { + ...E2E_PARTNERS[0].shortLink, + }, + }); + + expect(clickResponse.status).toEqual(200); + + const clickId = clickResponse.data.clickId; + const customer = randomCustomer(); + + // Track the lead + const trackLeadResponse = await http.post({ + path: "/track/lead", + body: { + clickId, + eventName: "Signup", + customerExternalId: customer.externalId, + customerName: customer.name, + customerEmail: customer.email, + customerAvatar: customer.avatar, + }, + }); + + expect(trackLeadResponse.status).toEqual(200); + + // Verify the commission + await verifyCommission({ + http, + customerExternalId: customer.externalId, + expectedEarnings: E2E_LEAD_REWARD.modifiers[0].amountInCents, + }); + }); + + test("when {Partner} {Country} is {CA}", async () => { + // Track the click + const clickResponse = await http.post<{ clickId: string }>({ + path: "/track/click", + headers: E2E_TRACK_CLICK_HEADERS, + body: { + ...E2E_PARTNERS[1].shortLink, + }, + }); + + expect(clickResponse.status).toEqual(200); + + const clickId = clickResponse.data.clickId; + const customer = randomCustomer(); + + // Track the lead + const trackLeadResponse = await http.post({ + path: "/track/lead", + body: { + clickId, + eventName: "Signup", + customerExternalId: customer.externalId, + customerName: customer.name, + customerEmail: customer.email, + customerAvatar: customer.avatar, + }, + }); + + expect(trackLeadResponse.status).toEqual(200); + + // Verify the commission + await verifyCommission({ + http, + customerExternalId: customer.externalId, + expectedEarnings: E2E_LEAD_REWARD.modifiers[1].amountInCents, + }); + }); + + test("when {Partner} {Country} is not {US} or {CA}", async () => { + // Track the click + const clickResponse = await http.post<{ clickId: string }>({ + path: "/track/click", + headers: E2E_TRACK_CLICK_HEADERS, + body: { + ...E2E_PARTNERS[2].shortLink, + }, + }); + + expect(clickResponse.status).toEqual(200); + + const clickId = clickResponse.data.clickId; + const customer = randomCustomer(); + + // Track the lead + const trackLeadResponse = await http.post({ + path: "/track/lead", + body: { + clickId, + eventName: "Signup", + customerExternalId: customer.externalId, + customerName: customer.name, + customerEmail: customer.email, + customerAvatar: customer.avatar, + }, + }); + + expect(trackLeadResponse.status).toEqual(200); + + // Verify the commission + await verifyCommission({ + http, + customerExternalId: customer.externalId, + expectedEarnings: E2E_LEAD_REWARD.amountInCents, + }); + }); +}); diff --git a/apps/web/tests/tracks/track-lead.test.ts b/apps/web/tests/tracks/track-lead.test.ts index 53921ac8512..cb1d5cbec5e 100644 --- a/apps/web/tests/tracks/track-lead.test.ts +++ b/apps/web/tests/tracks/track-lead.test.ts @@ -1,12 +1,7 @@ -import { - CommissionResponse, - Customer, - TrackLeadResponse, - TrackSaleResponse, -} from "@/lib/types"; +import { TrackLeadResponse, TrackSaleResponse } from "@/lib/types"; import { randomCustomer } from "tests/utils/helpers"; -import { HttpClient } from "tests/utils/http"; import { E2E_LEAD_REWARD, E2E_TRACK_CLICK_HEADERS } from "tests/utils/resource"; +import { verifyCommission } from "tests/utils/verify-commission"; import { describe, expect, test } from "vitest"; import { IntegrationHarness } from "../utils/integration"; @@ -30,39 +25,6 @@ const expectValidLeadResponse = ({ }); }; -const verifyCommission = async ({ - http, - customerExternalId, - expectedEarnings, -}: { - http: HttpClient; - customerExternalId: string; - expectedEarnings: number; -}) => { - // Find the customer first - const { data: customers } = await http.get({ - path: "/customers", - query: { - externalId: customerExternalId, - }, - }); - - const customer = customers[0]; - - // Find the commission for the customer - const { status, data: commissions } = await http.get({ - 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(); diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.ts index 67221a21284..2721cffaa73 100644 --- a/apps/web/tests/utils/resource.ts +++ b/apps/web/tests/utils/resource.ts @@ -72,15 +72,15 @@ export const E2E_SALE_REWARD = { }, ], }; + export const E2E_LEAD_REWARD = { id: "rw_1K82ESAT4YPY0STR20GKXZ7DR", event: "lead", type: "flat", - amountInCents: 1000, + amountInCents: 100, modifiers: [ { type: "flat", - amountInCents: 200, operator: "AND", conditions: [ { @@ -91,6 +91,21 @@ export const E2E_LEAD_REWARD = { }, ], maxDuration: null, + amountInCents: 200, + }, + { + type: "flat", + operator: "AND", + conditions: [ + { + value: "CA", + entity: "partner", + operator: "equals_to", + attribute: "country", + }, + ], + maxDuration: 0, + amountInCents: 300, }, ], }; @@ -128,3 +143,30 @@ export const E2E_PARTNER_GROUP = { id: "grp_1K2E25381GVMG7HHM057TB92F", url: "https://acme.dub.sh/", }; + +export const E2E_PARTNERS = [ + { + id: "pn_H4TB2V5hDIjpqB7PwrxESoY3", + country: "US", + shortLink: { + domain: "getacme.link", + key: "derek", + }, + }, + { + id: "pn_NNG3YjwhLhA7nCZSaXeLIsWu", + country: "CA", + shortLink: { + domain: "getacme.link", + key: "marvin", + }, + }, + { + id: "pn_OfewI1Faaf5pV8QH3mha8L7S", + country: "IN", + shortLink: { + domain: "getacme.link", + key: "kirankk", + }, + }, +] as const; diff --git a/apps/web/tests/utils/verify-commission.ts b/apps/web/tests/utils/verify-commission.ts new file mode 100644 index 00000000000..6510ef05c70 --- /dev/null +++ b/apps/web/tests/utils/verify-commission.ts @@ -0,0 +1,38 @@ +import { CommissionResponse, Customer } from "@/lib/types"; +import { expect } from "vitest"; +import { HttpClient } from "./http"; + +export const verifyCommission = async ({ + http, + customerExternalId, + expectedEarnings, +}: { + http: HttpClient; + customerExternalId: string; + expectedEarnings: number; +}) => { + // Find the customer first + const { data: customers } = await http.get({ + path: "/customers", + query: { + externalId: customerExternalId, + }, + }); + + const customer = customers[0]; + + await new Promise((resolve) => setTimeout(resolve, 2000)); + + // Find the commission for the customer + const { status, data: commissions } = await http.get({ + 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); +}; From c266dfcdc92d422b265eecb8b73c85bd3be3850e Mon Sep 17 00:00:00 2001 From: Kiran K Date: Tue, 28 Oct 2025 17:32:03 +0530 Subject: [PATCH 3/6] Refactor and expand rewards tests and utilities --- .../{index.test.ts => lead-reward.test.ts} | 42 +--------- apps/web/tests/rewards/sale-reward.test.ts | 65 ++++++++++++++++ apps/web/tests/tracks/track-lead.test.ts | 43 +---------- apps/web/tests/tracks/track-sale.test.ts | 62 ++++++--------- apps/web/tests/utils/resource.ts | 77 ++++++++++++------- apps/web/tests/utils/verify-commission.ts | 71 ++++++++++++----- 6 files changed, 190 insertions(+), 170 deletions(-) rename apps/web/tests/rewards/{index.test.ts => lead-reward.test.ts} (67%) create mode 100644 apps/web/tests/rewards/sale-reward.test.ts diff --git a/apps/web/tests/rewards/index.test.ts b/apps/web/tests/rewards/lead-reward.test.ts similarity index 67% rename from apps/web/tests/rewards/index.test.ts rename to apps/web/tests/rewards/lead-reward.test.ts index 9f8a0f24e1a..990167233e9 100644 --- a/apps/web/tests/rewards/index.test.ts +++ b/apps/web/tests/rewards/lead-reward.test.ts @@ -9,7 +9,7 @@ import { verifyCommission } from "tests/utils/verify-commission"; import { describe, expect, test } from "vitest"; import { IntegrationHarness } from "../utils/integration"; -describe.concurrent("Rewards based on partner's country", async () => { +describe.concurrent("Lead rewards", async () => { const h = new IntegrationHarness(); const { http } = await h.init(); @@ -51,7 +51,7 @@ describe.concurrent("Rewards based on partner's country", async () => { }); }); - test("when {Partner} {Country} is {CA}", async () => { + test("when {Partner} {Country} is not {US}", async () => { // Track the click const clickResponse = await http.post<{ clickId: string }>({ path: "/track/click", @@ -81,44 +81,6 @@ describe.concurrent("Rewards based on partner's country", async () => { expect(trackLeadResponse.status).toEqual(200); - // Verify the commission - await verifyCommission({ - http, - customerExternalId: customer.externalId, - expectedEarnings: E2E_LEAD_REWARD.modifiers[1].amountInCents, - }); - }); - - test("when {Partner} {Country} is not {US} or {CA}", async () => { - // Track the click - const clickResponse = await http.post<{ clickId: string }>({ - path: "/track/click", - headers: E2E_TRACK_CLICK_HEADERS, - body: { - ...E2E_PARTNERS[2].shortLink, - }, - }); - - expect(clickResponse.status).toEqual(200); - - const clickId = clickResponse.data.clickId; - const customer = randomCustomer(); - - // Track the lead - const trackLeadResponse = await http.post({ - path: "/track/lead", - body: { - clickId, - eventName: "Signup", - customerExternalId: customer.externalId, - customerName: customer.name, - customerEmail: customer.email, - customerAvatar: customer.avatar, - }, - }); - - expect(trackLeadResponse.status).toEqual(200); - // Verify the commission await verifyCommission({ http, diff --git a/apps/web/tests/rewards/sale-reward.test.ts b/apps/web/tests/rewards/sale-reward.test.ts new file mode 100644 index 00000000000..e49e0511b73 --- /dev/null +++ b/apps/web/tests/rewards/sale-reward.test.ts @@ -0,0 +1,65 @@ +import { TrackSaleResponse } from "@/lib/types"; +import { randomId } from "tests/utils/helpers"; +import { E2E_CUSTOMERS, E2E_SALE_REWARD } from "tests/utils/resource"; +import { verifyCommission } from "tests/utils/verify-commission"; +import { describe, expect, test } from "vitest"; +import { IntegrationHarness } from "../utils/integration"; + +describe.concurrent("Sale rewards", async () => { + const h = new IntegrationHarness(); + const { http } = await h.init(); + + test("when {Customer} {Country} is {US}", async () => { + const saleAmount = 10000; // $100 in cents + const invoiceId = `INV_${randomId()}`; + + // Track the sale + const trackSaleResponse = await http.post({ + path: "/track/sale", + body: { + customerExternalId: E2E_CUSTOMERS[0].externalId, + eventName: "Subscription", + amount: saleAmount, + currency: "usd", + invoiceId, + paymentProcessor: "stripe", + }, + }); + + expect(trackSaleResponse.status).toEqual(200); + + // Verify the commission (10% of sale amount) + await verifyCommission({ + http, + invoiceId, + expectedEarnings: saleAmount * 0.1, + }); + }); + + test.skip("when {Customer} {Country} is not {US}", async () => { + const saleAmount = 10000; // $100 in cents + const invoiceId = `INV_${randomId()}`; + + // Track the sale + const trackSaleResponse = await http.post({ + path: "/track/sale", + body: { + customerExternalId: E2E_CUSTOMERS[1].externalId, + eventName: "Subscription", + amount: saleAmount, + currency: "usd", + invoiceId, + paymentProcessor: "stripe", + }, + }); + + expect(trackSaleResponse.status).toEqual(200); + + // Verify the commission (base reward) + await verifyCommission({ + http, + invoiceId, + expectedEarnings: E2E_SALE_REWARD.amountInCents, + }); + }); +}); diff --git a/apps/web/tests/tracks/track-lead.test.ts b/apps/web/tests/tracks/track-lead.test.ts index cb1d5cbec5e..a1e7a83c21d 100644 --- a/apps/web/tests/tracks/track-lead.test.ts +++ b/apps/web/tests/tracks/track-lead.test.ts @@ -1,7 +1,6 @@ import { TrackLeadResponse, TrackSaleResponse } from "@/lib/types"; import { randomCustomer } from "tests/utils/helpers"; -import { E2E_LEAD_REWARD, E2E_TRACK_CLICK_HEADERS } from "tests/utils/resource"; -import { verifyCommission } from "tests/utils/verify-commission"; +import { E2E_TRACK_CLICK_HEADERS } from "tests/utils/resource"; import { describe, expect, test } from "vitest"; import { IntegrationHarness } from "../utils/integration"; @@ -216,44 +215,4 @@ 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({ - 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].amountInCents, - }); - }); }); diff --git a/apps/web/tests/tracks/track-sale.test.ts b/apps/web/tests/tracks/track-sale.test.ts index 562036082ff..2acbb45e1e5 100644 --- a/apps/web/tests/tracks/track-sale.test.ts +++ b/apps/web/tests/tracks/track-sale.test.ts @@ -11,6 +11,7 @@ import { E2E_SALE_REWARD, E2E_TRACK_CLICK_HEADERS, } from "tests/utils/resource"; +import { verifyCommission } from "tests/utils/verify-commission"; import { describe, expect, test } from "vitest"; import { IntegrationHarness } from "../utils/integration"; @@ -38,25 +39,6 @@ const expectValidSaleResponse = ( }); }; -// Helper function to verify commission details -const verifyCommission = async ( - http: any, - invoiceId: string, - expectedAmount: number, - expectedEarnings: number, -) => { - const { status, data: commissions } = await http.get({ - path: "/commissions", - query: { invoiceId }, - }); - - expect(status).toEqual(200); - expect(commissions).toHaveLength(1); - expect(commissions[0].invoiceId).toEqual(invoiceId); - expect(commissions[0].amount).toEqual(expectedAmount); - expect(commissions[0].earnings).toEqual(expectedEarnings); -}; - describe("POST /track/sale", async () => { const h = new IntegrationHarness(); const { http } = await h.init(); @@ -129,19 +111,19 @@ describe("POST /track/sale", async () => { // pause for 2 seconds for data to be fully processed await new Promise((resolve) => setTimeout(resolve, 2000)); - // Verify commissions - await verifyCommission( + await verifyCommission({ http, - regularInvoiceId, - response1.data.sale?.amount!, - E2E_SALE_REWARD.amountInCents, - ); - await verifyCommission( + invoiceId: regularInvoiceId, + expectedAmount: response1.data.sale?.amount!, + expectedEarnings: E2E_SALE_REWARD.amountInCents, + }); + + await verifyCommission({ http, - premiumInvoiceId, - response2.data.sale?.amount!, - E2E_SALE_REWARD.modifiers[0].amountInCents, - ); + invoiceId: premiumInvoiceId, + expectedAmount: response2.data.sale?.amount!, + expectedEarnings: E2E_SALE_REWARD.modifiers[0].amountInCents!, + }); }); test("track a sale with an externalId that does not exist (should return null customer and sale)", async () => { @@ -311,18 +293,18 @@ describe("POST /track/sale", async () => { // Pause for 2 seconds for data to be fully processed await new Promise((resolve) => setTimeout(resolve, 2000)); - await verifyCommission( + await verifyCommission({ http, - smallSaleInvoiceId, - response1.data.sale?.amount!, - E2E_SALE_REWARD.amountInCents, - ); + invoiceId: smallSaleInvoiceId, + expectedAmount: response1.data.sale?.amount!, + expectedEarnings: E2E_SALE_REWARD.amountInCents, + }); - await verifyCommission( + await verifyCommission({ http, - largeSaleInvoiceId, - response2.data.sale?.amount!, - E2E_SALE_REWARD.modifiers[1].amountInCents, - ); + invoiceId: largeSaleInvoiceId, + expectedAmount: response2.data.sale?.amount!, + expectedEarnings: E2E_SALE_REWARD.modifiers[1].amountInCents!, + }); }); }); diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.ts index 2721cffaa73..0d81047e508 100644 --- a/apps/web/tests/utils/resource.ts +++ b/apps/web/tests/utils/resource.ts @@ -45,53 +45,46 @@ export const E2E_SALE_REWARD = { amountInCents: 1000, modifiers: [ { - operator: "AND", type: "flat", - amountInCents: 3000, + operator: "AND", conditions: [ { + value: "premiumProductId", entity: "sale", - attribute: "productId", operator: "equals_to", - value: "premiumProductId", + attribute: "productId", }, ], + maxDuration: null, + amountInCents: 3000, }, { - operator: "AND", type: "flat", - amountInCents: 5000, + operator: "AND", conditions: [ { + value: 15000, entity: "sale", - attribute: "amount", operator: "greater_than", - value: 15000, + attribute: "amount", }, ], + maxDuration: null, + amountInCents: 5000, }, - ], -}; - -export const E2E_LEAD_REWARD = { - id: "rw_1K82ESAT4YPY0STR20GKXZ7DR", - event: "lead", - type: "flat", - amountInCents: 100, - modifiers: [ { - type: "flat", + type: "percentage", operator: "AND", conditions: [ { value: "US", - entity: "partner", + entity: "customer", operator: "equals_to", attribute: "country", }, ], maxDuration: null, - amountInCents: 200, + amountInPercentage: 10, }, { type: "flat", @@ -99,13 +92,36 @@ export const E2E_LEAD_REWARD = { conditions: [ { value: "CA", + entity: "customer", + operator: "equals_to", + attribute: "country", + }, + ], + maxDuration: null, + amountInCents: 50, + }, + ], +}; + +export const E2E_LEAD_REWARD = { + id: "rw_1K82ESAT4YPY0STR20GKXZ7DR", + event: "lead", + type: "flat", + amountInCents: 100, + modifiers: [ + { + type: "flat", + operator: "AND", + conditions: [ + { + value: "US", entity: "partner", operator: "equals_to", attribute: "country", }, ], - maxDuration: 0, - amountInCents: 300, + maxDuration: null, + amountInCents: 200, }, ], }; @@ -161,12 +177,17 @@ export const E2E_PARTNERS = [ key: "marvin", }, }, +] as const; + +export const E2E_CUSTOMERS = [ { - id: "pn_OfewI1Faaf5pV8QH3mha8L7S", - country: "IN", - shortLink: { - domain: "getacme.link", - key: "kirankk", - }, + id: "cus_1K8N811NNX9BJSBWGG3S567VG", + externalId: "cus_5akyQXRfzeFtCeUsCodaIlmf", + country: "US", + }, + { + id: "cus_1K86CG1DZFW8EMSSWXX4AVZFA", + externalId: "cus_vq3UgXINHS99MIon8vNvAO1n", + country: "CA", }, ] as const; diff --git a/apps/web/tests/utils/verify-commission.ts b/apps/web/tests/utils/verify-commission.ts index 6510ef05c70..94e9b5304ff 100644 --- a/apps/web/tests/utils/verify-commission.ts +++ b/apps/web/tests/utils/verify-commission.ts @@ -2,37 +2,68 @@ import { CommissionResponse, Customer } from "@/lib/types"; import { expect } from "vitest"; import { HttpClient } from "./http"; +interface VerifyCommissionProps { + http: HttpClient; + customerExternalId?: string; + invoiceId?: string; + expectedAmount?: number; + expectedEarnings: number; +} + export const verifyCommission = async ({ http, customerExternalId, + invoiceId, + expectedAmount, expectedEarnings, -}: { - http: HttpClient; - customerExternalId: string; - expectedEarnings: number; -}) => { - // Find the customer first - const { data: customers } = await http.get({ - path: "/customers", - query: { - externalId: customerExternalId, - }, - }); +}: VerifyCommissionProps) => { + let customerId: string | undefined; + + // Optional: resolve customer ID if customerExternalId is given + if (customerExternalId) { + const { data: customers } = await http.get({ + path: "/customers", + query: { externalId: customerExternalId }, + }); + + expect(customers.length).toBeGreaterThan(0); + customerId = customers[0].id; - const customer = customers[0]; + // Small delay if necessary for async commission processing + await new Promise((resolve) => setTimeout(resolve, 2000)); + } - await new Promise((resolve) => setTimeout(resolve, 2000)); + const query: Record = {}; + + if (invoiceId) { + query.invoiceId = invoiceId; + } + + if (customerId) { + query.customerId = customerId; + } - // Find the commission for the customer const { status, data: commissions } = await http.get({ path: "/commissions", - query: { - customerId: customer.id, - }, + query, }); expect(status).toEqual(200); expect(commissions).toHaveLength(1); - expect(commissions[0].customer?.id).toEqual(customer.id); - expect(commissions[0].earnings).toEqual(expectedEarnings); + + const commission = commissions[0]; + + if (invoiceId) { + expect(commission.invoiceId).toEqual(invoiceId); + } + + if (customerId) { + expect(commission.customer?.id).toEqual(customerId); + } + + if (expectedAmount !== undefined) { + expect(commission.amount).toEqual(expectedAmount); + } + + expect(commission.earnings).toEqual(expectedEarnings); }; From b088e484ba3b1c52fa2450f54877a57eecc03bf0 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Tue, 28 Oct 2025 17:45:48 +0530 Subject: [PATCH 4/6] fix tests --- apps/web/tests/rewards/sale-reward.test.ts | 4 ++-- apps/web/tests/utils/resource.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/web/tests/rewards/sale-reward.test.ts b/apps/web/tests/rewards/sale-reward.test.ts index e49e0511b73..27bdf0ced11 100644 --- a/apps/web/tests/rewards/sale-reward.test.ts +++ b/apps/web/tests/rewards/sale-reward.test.ts @@ -9,7 +9,7 @@ describe.concurrent("Sale rewards", async () => { const h = new IntegrationHarness(); const { http } = await h.init(); - test("when {Customer} {Country} is {US}", async () => { + test("when {Customer} {Country} is {SG}", async () => { const saleAmount = 10000; // $100 in cents const invoiceId = `INV_${randomId()}`; @@ -36,7 +36,7 @@ describe.concurrent("Sale rewards", async () => { }); }); - test.skip("when {Customer} {Country} is not {US}", async () => { + test.skip("when {Customer} {Country} is {CA}", async () => { const saleAmount = 10000; // $100 in cents const invoiceId = `INV_${randomId()}`; diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.ts index 0d81047e508..3bf69f5982c 100644 --- a/apps/web/tests/utils/resource.ts +++ b/apps/web/tests/utils/resource.ts @@ -181,9 +181,9 @@ export const E2E_PARTNERS = [ export const E2E_CUSTOMERS = [ { - id: "cus_1K8N811NNX9BJSBWGG3S567VG", - externalId: "cus_5akyQXRfzeFtCeUsCodaIlmf", - country: "US", + id: "cus_1K82FYFF7RANMCGRHRGMWDNEC", + externalId: "cus_LnZbkb8boLsOn1YGLPxZGZMU", + country: "SG", }, { id: "cus_1K86CG1DZFW8EMSSWXX4AVZFA", From 1e3a179cf472b01b31dbfc88fdadba208a480e5a Mon Sep 17 00:00:00 2001 From: Kiran K Date: Tue, 28 Oct 2025 18:06:57 +0530 Subject: [PATCH 5/6] Update resource.ts --- apps/web/tests/utils/resource.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.ts index 3bf69f5982c..a77ccb97c48 100644 --- a/apps/web/tests/utils/resource.ts +++ b/apps/web/tests/utils/resource.ts @@ -123,6 +123,20 @@ export const E2E_LEAD_REWARD = { maxDuration: null, amountInCents: 200, }, + { + type: "flat", + operator: "AND", + conditions: [ + { + value: "US", + entity: "customer", + operator: "equals_to", + attribute: "country", + }, + ], + maxDuration: null, + amountInCents: 400, + }, ], }; @@ -170,11 +184,11 @@ export const E2E_PARTNERS = [ }, }, { - id: "pn_NNG3YjwhLhA7nCZSaXeLIsWu", - country: "CA", + id: "pn_1K8ND11BZ4XPEX39QX3YMBGY0", + country: "SG", shortLink: { domain: "getacme.link", - key: "marvin", + key: "kiran-e2e-1", }, }, ] as const; From 774a5c2c7e5a48840a206f0ecf5488fbd6b22750 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Tue, 28 Oct 2025 18:18:53 +0530 Subject: [PATCH 6/6] Update resource.ts --- apps/web/tests/utils/resource.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.ts index a77ccb97c48..6aefc236eb2 100644 --- a/apps/web/tests/utils/resource.ts +++ b/apps/web/tests/utils/resource.ts @@ -176,11 +176,11 @@ export const E2E_PARTNER_GROUP = { export const E2E_PARTNERS = [ { - id: "pn_H4TB2V5hDIjpqB7PwrxESoY3", + id: "pn_NNG3YjwhLhA7nCZSaXeLIsWu", country: "US", shortLink: { domain: "getacme.link", - key: "derek", + key: "marvin", }, }, {