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.

finalize rewards/sale-reward tests

Steven Teye77a43ecbee3
diff --git a/apps/web/tests/rewards/sale-reward.test.ts b/apps/web/tests/rewards/sale-reward.test.ts
index fd304fee1f..518c1f8289 100644
--- a/apps/web/tests/rewards/sale-reward.test.ts
+++ b/apps/web/tests/rewards/sale-reward.test.ts
@@ -1,10 +1,14 @@
import { TrackSaleResponse } from "@/lib/types";
-import { randomId, randomSaleAmount } from "tests/utils/helpers";
import {
- E2E_CUSTOMER_EXTERNAL_ID_2,
- E2E_CUSTOMER_SG_EXTERNAL_ID,
- E2E_CUSTOMER_SUB_DURATION_EXTERNAL_ID,
+ randomCustomer,
+ randomId,
+ randomSaleAmount,
+} from "tests/utils/helpers";
+import {
+ E2E_CUSTOMER_COUNTRY_CONDITIONS_EXTERNAL_ID,
+ E2E_CUSTOMER_SALE_CONDITIONS_EXTERNAL_ID,
E2E_SALE_REWARD,
+ E2E_TRACK_CLICK_HEADERS,
} from "tests/utils/resource";
import { verifyCommission } from "tests/utils/verify-commission";
import { describe, expect, test } from "vitest";
@@ -14,8 +18,8 @@ describe.concurrent("Sale rewards with conditions", async () => {
const h = new IntegrationHarness();
const { http } = await h.init();
- const randomSale = () => ({
- eventName: "Subscription",
+ const randomSale = (eventName = "Payment") => ({
+ eventName,
currency: "usd",
paymentProcessor: "stripe",
amount: randomSaleAmount(),
@@ -23,13 +27,13 @@ describe.concurrent("Sale rewards with conditions", async () => {
});
test("When {Sale} {Product ID} is {regularProductId}", async () => {
- const sale = randomSale();
+ const sale = randomSale("E2E base condition");
const response = await http.post<TrackSaleResponse>({
path: "/track/sale",
body: {
...sale,
- customerExternalId: E2E_CUSTOMER_EXTERNAL_ID_2,
+ customerExternalId: E2E_CUSTOMER_SALE_CONDITIONS_EXTERNAL_ID,
metadata: {
productId: "regularProductId",
},
@@ -46,13 +50,13 @@ describe.concurrent("Sale rewards with conditions", async () => {
});
test("When {Sale} {Product ID} is {premiumProductId}", async () => {
- const sale = randomSale();
+ const sale = randomSale("E2E sale product ID condition");
const response = await http.post<TrackSaleResponse>({
path: "/track/sale",
body: {
...sale,
- customerExternalId: E2E_CUSTOMER_EXTERNAL_ID_2,
+ customerExternalId: E2E_CUSTOMER_SALE_CONDITIONS_EXTERNAL_ID,
metadata: {
productId: "premiumProductId",
},
@@ -69,14 +73,14 @@ describe.concurrent("Sale rewards with conditions", async () => {
});
test("When {Sale} {Amount} is greater than {15000}", async () => {
- const sale = randomSale();
+ const sale = randomSale("E2E sale amount condition");
const response = await http.post<TrackSaleResponse>({
path: "/track/sale",
body: {
...sale,
amount: 17500,
- customerExternalId: E2E_CUSTOMER_EXTERNAL_ID_2,
+ customerExternalId: E2E_CUSTOMER_SALE_CONDITIONS_EXTERNAL_ID,
metadata: {
productId: "premiumProductId",
},
@@ -93,13 +97,13 @@ describe.concurrent("Sale rewards with conditions", async () => {
});
test("when {Customer} {Country} is {SG}", async () => {
- const sale = randomSale();
+ const sale = randomSale("E2E customer country condition");
const trackSaleResponse = await http.post<TrackSaleResponse>({
path: "/track/sale",
body: {
...sale,
- customerExternalId: E2E_CUSTOMER_SG_EXTERNAL_ID,
+ customerExternalId: E2E_CUSTOMER_COUNTRY_CONDITIONS_EXTERNAL_ID,
},
});
@@ -112,14 +116,31 @@ describe.concurrent("Sale rewards with conditions", async () => {
});
});
- test("when {Customer} {Subscription Duration} is greater than {12}", async () => {
- const sale = randomSale();
+ test("when {Customer} {Subscription Duration} is {less than or equal to} {3}", async () => {
+ const clickResponse = await http.post<{ clickId: string }>({
+ path: "/track/click",
+ headers: E2E_TRACK_CLICK_HEADERS,
+ body: {
+ domain: "getacme.link",
+ key: "marvin",
+ },
+ });
+ expect(clickResponse.status).toEqual(200);
+ const trackedClickId = clickResponse.data.clickId;
+ expect(trackedClickId).toStrictEqual(expect.any(String));
+ const newCustomer = randomCustomer();
+ const sale = randomSale("E2E customer subscription duration condition");
+ // here we use direct sale tracking to save time
const trackSaleResponse = await http.post<TrackSaleResponse>({
path: "/track/sale",
body: {
...sale,
- customerExternalId: E2E_CUSTOMER_SUB_DURATION_EXTERNAL_ID,
+ clickId: trackedClickId,
+ customerExternalId: newCustomer.externalId,
+ customerName: newCustomer.name,
+ customerEmail: newCustomer.email,
+ customerAvatar: newCustomer.avatar,
},
});
diff --git a/apps/web/tests/tracks/track-sale.test.ts b/apps/web/tests/tracks/track-sale.test.ts
index 0e3cd7a238..bab5fc87ba 100644
--- a/apps/web/tests/tracks/track-sale.test.ts
+++ b/apps/web/tests/tracks/track-sale.test.ts
@@ -6,12 +6,9 @@ import {
} from "tests/utils/helpers";
import {
E2E_CUSTOMER_EXTERNAL_ID,
- E2E_CUSTOMER_EXTERNAL_ID_2,
E2E_CUSTOMER_ID,
- 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";
@@ -205,58 +202,4 @@ describe.concurrent("POST /track/sale", async () => {
},
});
});
-
- test("track sales with different amounts (verifies sale amount is passed via context for reward conditions)", async () => {
- // Test with a small sale amount
- const smallSaleInvoiceId = `INV_${randomId()}`;
- const smallSaleAmount = 10000; // $100.00
-
- // Test with a large sale amount
- const largeSaleInvoiceId = `INV_${randomId()}`;
- const largeSaleAmount = 20000; // $200.00
-
- const [response1, response2] = await Promise.all([
- http.post<TrackSaleResponse>({
- path: "/track/sale",
- body: {
- ...sale,
- amount: smallSaleAmount,
- customerExternalId: E2E_CUSTOMER_EXTERNAL_ID_2,
- invoiceId: smallSaleInvoiceId,
- },
- }),
-
- http.post<TrackSaleResponse>({
- path: "/track/sale",
- body: {
- ...sale,
- amount: largeSaleAmount,
- customerExternalId: E2E_CUSTOMER_EXTERNAL_ID_2,
- invoiceId: largeSaleInvoiceId,
- },
- }),
- ]);
-
- expect(response1.status).toEqual(200);
- expect(response1.data.sale?.amount).toEqual(smallSaleAmount);
-
- expect(response2.status).toEqual(200);
- expect(response2.data.sale?.amount).toEqual(largeSaleAmount);
-
- 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!,
- }),
- ]);
- });
});
diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.ts
index 18681e2622..4fb92fe124 100644
--- a/apps/web/tests/utils/resource.ts
+++ b/apps/web/tests/utils/resource.ts
@@ -26,13 +26,6 @@ export const E2E_TAG_2 = {
color: "blue",
};
-export const E2E_CUSTOMER_ID = "cm25onzuv0001s1bbxchrc0ae";
-export const E2E_CUSTOMER_EXTERNAL_ID = "cus_jTrfVKYN3Buc3F80JoqBiY0g";
-export const E2E_CUSTOMER_EXTERNAL_ID_2 = "cus_pqc8qRtofpu6ZqvutyNDGAU2";
-export const E2E_CUSTOMER_SG_EXTERNAL_ID = "cus_LnZbkb8boLsOn1YGLPxZGZMU";
-export const E2E_CUSTOMER_SUB_DURATION_EXTERNAL_ID =
- "cus_TlwjnmJb4Fa8lU8IA5Dg0uzo";
-
export const E2E_WEBHOOK_ID = "wh_MHR7sZXXtZ7keBaNYZ30rQ0v";
// Folders specific
@@ -42,6 +35,14 @@ export const E2E_NO_ACCESS_FOLDER_ID = "fold_1JRZXGNNYWDA5QTT8CVDB3M23"; // Fold
export const E2E_READ_ONLY_FOLDER_LINK_ID = "link_1KAESR5Z733716RTT4E1RSTW6"; // A link in read-only folder
export const E2E_NO_ACCESS_FOLDER_LINK_ID = "link_1KAESQ2Z6Q35WDV5NGSEVPFB0"; // A link in no access folder
+// Different customer external IDs for different reward conditions
+export const E2E_CUSTOMER_ID = "cm25onzuv0001s1bbxchrc0ae";
+export const E2E_CUSTOMER_EXTERNAL_ID = "cus_jTrfVKYN3Buc3F80JoqBiY0g";
+export const E2E_CUSTOMER_SALE_CONDITIONS_EXTERNAL_ID =
+ "cus_pqc8qRtofpu6ZqvutyNDGAU2";
+export const E2E_CUSTOMER_COUNTRY_CONDITIONS_EXTERNAL_ID =
+ "cus_LnZbkb8boLsOn1YGLPxZGZMU";
+
// Rewards specific
export const E2E_SALE_REWARD = {
id: "rw_1JYPP77NNDG6TVPAJDKNZREQN",
@@ -102,12 +103,12 @@ export const E2E_SALE_REWARD = {
{
value: 3,
entity: "customer",
- operator: "greater_than",
+ operator: "less_than_or_equal",
attribute: "subscriptionDurationMonths",
},
],
maxDuration: null,
- amountInCents: 500,
+ amountInCents: 2000,
},
],
};