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.

Merge branch 'main' into feat/workflow-e2e-tests

Pedro Ladeira0deacdf0580f
diff --cc apps/web/tests/rewards/sale-reward.test.ts
index 89d6c0b5cb,518c1f8289..c03b176d99
--- a/apps/web/tests/rewards/sale-reward.test.ts
+++ b/apps/web/tests/rewards/sale-reward.test.ts
@@@ -9,11 -18,87 +18,84 @@@ describe.concurrent("Sale rewards with
const h = new IntegrationHarness();
const { http } = await h.init();
+ const randomSale = (eventName = "Payment") => ({
+ eventName,
+ currency: "usd",
+ paymentProcessor: "stripe",
+ amount: randomSaleAmount(),
+ invoiceId: `INV_${randomId()}`,
+ });
+
+ test("When {Sale} {Product ID} is {regularProductId}", async () => {
+ const sale = randomSale("E2E base condition");
+
+ const response = await http.post<TrackSaleResponse>({
+ path: "/track/sale",
+ body: {
+ ...sale,
+ customerExternalId: E2E_CUSTOMER_SALE_CONDITIONS_EXTERNAL_ID,
+ metadata: {
+ productId: "regularProductId",
+ },
+ },
+ });
+
+ expect(response.status).toEqual(200);
+
+ await verifyCommission({
- http,
+ invoiceId: sale.invoiceId,
+ expectedEarnings: E2E_SALE_REWARD.amountInCents,
+ });
+ });
+
+ test("When {Sale} {Product ID} is {premiumProductId}", async () => {
+ const sale = randomSale("E2E sale product ID condition");
+
+ const response = await http.post<TrackSaleResponse>({
+ path: "/track/sale",
+ body: {
+ ...sale,
+ customerExternalId: E2E_CUSTOMER_SALE_CONDITIONS_EXTERNAL_ID,
+ metadata: {
+ productId: "premiumProductId",
+ },
+ },
+ });
+
+ expect(response.status).toEqual(200);
+
+ await verifyCommission({
- http,
+ invoiceId: sale.invoiceId,
+ expectedEarnings: E2E_SALE_REWARD.modifiers[0].amountInCents!,
+ });
+ });
+
+ test("When {Sale} {Amount} is greater than {15000}", async () => {
+ const sale = randomSale("E2E sale amount condition");
+
+ const response = await http.post<TrackSaleResponse>({
+ path: "/track/sale",
+ body: {
+ ...sale,
+ amount: 17500,
+ customerExternalId: E2E_CUSTOMER_SALE_CONDITIONS_EXTERNAL_ID,
+ metadata: {
+ productId: "premiumProductId",
+ },
+ },
+ });
+
+ expect(response.status).toEqual(200);
+
+ await verifyCommission({
- http,
+ invoiceId: sale.invoiceId,
+ expectedEarnings: E2E_SALE_REWARD.modifiers[1].amountInCents!,
+ });
+ });
+
test("when {Customer} {Country} is {SG}", async () => {
- const saleAmount = 10000; // $100 in cents
- const invoiceId = `INV_${randomId()}`;
+ const sale = randomSale("E2E customer country condition");
- // Track the sale
const trackSaleResponse = await http.post<TrackSaleResponse>({
path: "/track/sale",
body: {
@@@ -28,10 -109,10 +106,9 @@@
expect(trackSaleResponse.status).toEqual(200);
- // Verify the commission (10% of sale amount)
await verifyCommission({
- invoiceId,
- expectedEarnings: saleAmount * 0.1,
- http,
+ invoiceId: sale.invoiceId,
+ expectedEarnings: E2E_SALE_REWARD.modifiers[2].amountInCents!,
});
});
@@@ -54,10 -146,10 +142,9 @@@
expect(trackSaleResponse.status).toEqual(200);
- // Verify the commission (base reward)
await verifyCommission({
- invoiceId,
- expectedEarnings: E2E_SALE_REWARD.amountInCents,
- http,
+ invoiceId: sale.invoiceId,
+ expectedEarnings: E2E_SALE_REWARD.modifiers[3].amountInCents!,
});
});
});