-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add partner.country to reward conditions #2987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
💡 Enable Vercel Agent with $100 free credit for automated AI reviews |
WalkthroughLoads partner on program enrollment calls and threads partner.country into reward evaluation and schemas, plus adds tests and test fixtures to validate partner country-based reward conditions and end-to-end lead/sale commission assertions. Changes
Sequence Diagram(s)sequenceDiagram
participant API as Track / Commission API
participant Service as ProgramEnrollment Service
participant Reward as Reward Evaluator
participant DB as Commissions DB
rect rgb(230,247,255)
API->>Service: getProgramEnrollmentOrThrow(id, include: { links, saleReward, partner: true, ... })
Service-->>API: programEnrollment (includes partner with country)
end
rect rgb(245,255,230)
API->>Reward: evaluatePartnerReward(programEnrollment, event)
Note right of Reward: rewardContext.partner.country populated
Reward-->>API: rewardDecision (modifiers matched by country)
end
rect rgb(255,250,230)
API->>DB: createCommission(rewardDecision, enrollment, event)
DB-->>API: commission record
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/web/tests/tracks/track-lead.test.ts(4 hunks)apps/web/tests/tracks/track-sale.test.ts(3 hunks)apps/web/tests/utils/resource.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
apps/web/tests/tracks/track-sale.test.ts (1)
apps/web/tests/utils/resource.ts (1)
E2E_SALE_REWARD(41-71)
apps/web/tests/tracks/track-lead.test.ts (2)
apps/web/lib/types.ts (3)
Customer(417-417)CommissionResponse(434-434)TrackLeadResponse(413-413)apps/web/tests/utils/resource.ts (2)
E2E_LEAD_REWARD(72-92)E2E_TRACK_CLICK_HEADERS(10-14)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (6)
apps/web/tests/utils/resource.ts (2)
41-41: LGTM: Improved naming clarity.Renaming
E2E_REWARDtoE2E_SALE_REWARDmakes the purpose explicit and aligns with the addition ofE2E_LEAD_REWARD.
72-92: LGTM: Well-structured test fixture for partner country conditions.The new
E2E_LEAD_REWARDconstant properly supports testing the partner.country reward condition feature with appropriate base and modifier amounts.apps/web/tests/tracks/track-sale.test.ts (1)
11-11: LGTM: Consistent refactoring to use renamed constant.All references properly updated from
E2E_REWARDtoE2E_SALE_REWARDfollowing the rename in resource.ts.Also applies to: 137-137, 143-143, 318-318, 325-325
apps/web/tests/tracks/track-lead.test.ts (3)
1-9: LGTM: Necessary imports for commission verification.All new imports are properly utilized in the verifyCommission helper and the new test case.
102-109: LGTM: Proper commission verification with base reward amount.The addition verifies that the base reward amount (1000) is correctly applied when no modifiers match. The 2-second delay accommodates async processing.
264-302: The test assumes "marvin" link is associated with a US-based partner, but this dependency is undocumented and unverified.The test expects commission earnings of 200 (from
E2E_LEAD_REWARD.modifiers[0].amount), which triggers only whenpartner.country === "US". However, the test makes no explicit verification that the "marvin" link is owned by a US partner. The link appears to be pre-seeded in the test database outside this codebase, making the test brittle and dependent on external data setup.Recommendation: Either add an explicit assertion verifying the partner's country before checking earnings, or document that "marvin" is intentionally seeded as a US partner link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
apps/web/tests/tracks/track-lead.test.ts (1)
43-50: Add validation for empty customer array before accessingcustomers[0].The code accesses
customers[0]without verifying the array is non-empty, which will cause a runtime error if no customer matches theexternalId.Apply this diff to add the missing assertion:
const { data: customers } = await http.get<Customer[]>({ path: "/customers", query: { externalId: customerExternalId, }, }); +expect(customers).toHaveLength(1); const customer = customers[0];Based on learnings
🧹 Nitpick comments (1)
apps/web/tests/tracks/track-lead.test.ts (1)
289-289: Hardcoded sleep duration may cause flaky tests.The 2-second wait is arbitrary and could fail if commission processing takes longer in CI environments or under load.
Consider implementing a polling mechanism with timeout instead:
// Helper to poll for commission with retry const waitForCommission = async ( http: HttpClient, customerExternalId: string, maxAttempts = 10, delayMs = 500 ) => { for (let i = 0; i < maxAttempts; i++) { const { data: customers } = await http.get<Customer[]>({ path: "/customers", query: { externalId: customerExternalId }, }); if (customers.length > 0) { const { data: commissions } = await http.get<CommissionResponse[]>({ path: "/commissions", query: { customerId: customers[0].id }, }); if (commissions.length > 0) { return commissions[0]; } } await new Promise((resolve) => setTimeout(resolve, delayMs)); } throw new Error("Commission not found after polling"); };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/web/tests/tracks/track-lead.test.ts(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/tests/tracks/track-lead.test.ts (2)
apps/web/lib/types.ts (3)
Customer(417-417)CommissionResponse(434-434)TrackLeadResponse(413-413)apps/web/tests/utils/resource.ts (2)
E2E_TRACK_CLICK_HEADERS(10-14)E2E_LEAD_REWARD(72-92)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (1)
apps/web/tests/tracks/track-lead.test.ts (1)
258-296: Verify test assumptions and expected earnings calculation.This test has several assumptions that should be verified:
Partner country mapping: The test uses the "marvin" link and expects US partner behavior. Confirm that "marvin" is explicitly configured with
country: "US"in the test fixtures or setup.Earnings calculation: The test expects
E2E_LEAD_REWARD.modifiers[0].amount(200), butE2E_LEAD_REWARDhas a baseamount: 1000plus a modifier withamount: 200. Verify whether the expected earnings should be:
- Just the modifier: 200 (current implementation)
- Base + modifier: 1200
- Base amount only when conditions don't match
Run the following script to verify the "marvin" link configuration:
Summary by CodeRabbit
New Features
Tests