Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Oct 29, 2025

Summary by CodeRabbit

  • Tests
    • Renamed reward test cases to more descriptive, customer/partner country scenarios for clarity.
    • Updated assertions to match revised expected earnings for each scenario.
    • Adjusted test data for reward modifiers: swapped entity roles, updated modifier amounts and a modifier duration, to reflect current calculation scenarios.

@vercel
Copy link
Contributor

vercel bot commented Oct 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Oct 29, 2025 3:21pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

Walkthrough

Test names were made descriptive and E2E_LEAD_REWARD fixture modifiers were reworked: modifier entities swapped between customer and partner, one modifier's maxDuration set to 0 and amountInCents reduced from 400 to 300, and test assertions updated to reference different modifier indices/values.

Changes

Cohort / File(s) Summary
Lead reward test cases
apps/web/tests/rewards/lead-reward.test.ts
Renamed two test cases to explicit descriptions ("when customer country is US and partner country is US" and "when customer country is US and partner country is not US"). Updated expectedEarnings assertions to reference different modifier indices/values (first test: modifiers[0] → modifiers[1]; second test: E2E_LEAD_REWARD.amountInCents → modifiers[0]).
Lead reward test fixtures
apps/web/tests/utils/resource.ts
Modified E2E_LEAD_REWARD modifiers: first condition entity changed from partnercustomer; second modifier entity changed from customerpartner. Second modifier maxDuration changed from null0 and amountInCents changed from 400300. Operator remained equals_to.

Sequence Diagram(s)

(omitted — changes are test/fixture updates only; no runtime control-flow modifications to diagram)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify test names accurately reflect intended scenarios.
  • Confirm assertion index/value changes match the updated fixture modifier ordering and amounts.
  • Validate modifier entity swaps and the maxDuration/amount adjustments are intentional and consistent with reward logic.

Possibly related PRs

Suggested reviewers

  • steven-tey

Poem

🐰 A carrot for tests, neat and spry,
Modifiers hopped and swapped nearby.
Amounts trimmed, names now clear,
The rabbit cheers — the tests draw near! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title Check ❓ Inconclusive The title "Update rewards tests" is related to the changeset, which does modify reward-related tests and test data. However, the title is quite generic and doesn't convey the specific nature of the changes. The pull request involves multiple types of updates including renaming test cases for clarity, modifying test assertions with different data references, and updating test fixture values (E2E_LEAD_REWARD modifiers). The title doesn't clarify whether this is refactoring, bug fixing, or fixture maintenance, making it difficult for a teammate scanning history to understand the primary intent or scope of these changes. Consider revising the title to be more specific about the nature of the updates, such as "Refactor reward test cases and update test fixtures" or "Fix reward test assertions and rename test cases for clarity" to better communicate the primary changes and intent of the pull request.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch reward-e2e-tests

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98abd1a and 64e5bb3.

📒 Files selected for processing (1)
  • apps/web/tests/utils/resource.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-30T15:29:54.131Z
Learnt from: TWilson023
PR: dubinc/dub#2673
File: apps/web/ui/partners/rewards/rewards-logic.tsx:268-275
Timestamp: 2025-07-30T15:29:54.131Z
Learning: In apps/web/ui/partners/rewards/rewards-logic.tsx, when setting the entity field in a reward condition, dependent fields (attribute, operator, value) should be reset rather than preserved because different entities (customer vs sale) have different available attributes. Maintaining existing fields when the entity changes would create invalid state combinations and confusing UX.

Applied to files:

  • apps/web/tests/utils/resource.ts
🔇 Additional comments (2)
apps/web/tests/utils/resource.ts (2)

112-125: LGTM! Entity swap to customer is intentional.

The entity change from "partner" to "customer" aligns with the PR objectives. The condition checks if the customer's country is "US" and awards 200 cents accordingly.


126-139: No issues found. maxDuration: 0 has a well-defined semantic meaning in the codebase.

Based on codebase analysis, maxDuration: 0 consistently represents a "one-time" or "first transaction only" reward/discount, not an ambiguous value. The semantic is clearly distinguished:

  • maxDuration: null = lifetime (no expiration)
  • maxDuration: 0 = one-time only (first sale/purchase)
  • maxDuration: N > 0 = recurring for N months

This pattern is enforced across UI rendering, Stripe integration, commission logic, and validation schemas. The test modifier at lines 126–139 correctly applies maxDuration: 0 to define a one-time condition for partner rewards.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@devkiran devkiran changed the title Add more tests for rewards Update tests for rewards Oct 29, 2025
@devkiran devkiran changed the title Update tests for rewards Update rewards tests Oct 29, 2025
@devkiran devkiran marked this pull request as ready for review October 29, 2025 14:03
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/tests/rewards/lead-reward.test.ts (1)

16-50: Customer country is never set in either the helper or API request.

The test names claim "customer country is US", but randomCustomer() returns only { externalId, name, email, avatar } without a country field. Additionally, the /track/lead POST request body never includes customerCountry. Test 2 expects modifiers[0].amountInCents (200 cents), which requires the condition customer.country equals_to "US" to apply, but this condition cannot be met since the country is never provided to the endpoint.

The tests need either:

  • randomCustomer() to return country: "US", or
  • The track/lead request to include customerCountry: customer.country (after updating the helper)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d86b60 and 98abd1a.

📒 Files selected for processing (2)
  • apps/web/tests/rewards/lead-reward.test.ts (3 hunks)
  • apps/web/tests/utils/resource.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-30T15:29:54.131Z
Learnt from: TWilson023
PR: dubinc/dub#2673
File: apps/web/ui/partners/rewards/rewards-logic.tsx:268-275
Timestamp: 2025-07-30T15:29:54.131Z
Learning: In apps/web/ui/partners/rewards/rewards-logic.tsx, when setting the entity field in a reward condition, dependent fields (attribute, operator, value) should be reset rather than preserved because different entities (customer vs sale) have different available attributes. Maintaining existing fields when the entity changes would create invalid state combinations and confusing UX.

Applied to files:

  • apps/web/tests/utils/resource.ts
🧬 Code graph analysis (1)
apps/web/tests/rewards/lead-reward.test.ts (1)
apps/web/tests/utils/resource.ts (1)
  • E2E_LEAD_REWARD (106-141)
🔇 Additional comments (3)
apps/web/tests/utils/resource.ts (2)

118-118: Entity swap looks correct.

The entity change from "partner" to "customer" aligns with the updated test scenarios and maintains correct condition semantics.


137-138: Verify the maxDuration change from null to 0.

The maxDuration field semantics changed:

  • null typically means unlimited/indefinite duration
  • 0 might mean no duration, one-time reward, or could be treated differently by the rewards engine

Please confirm this change is intentional and that maxDuration: 0 produces the desired behavior for this test scenario.

apps/web/tests/rewards/lead-reward.test.ts (1)

54-88: Test expectations align with modifier logic.

The expectation correctly uses modifiers[0].amountInCents (200 cents) which triggers when customer country is US. Since the partner country is SG (not US), modifiers[1] won't trigger, making this the right assertion—assuming randomCustomer() sets country to US (see previous comment).

@steven-tey steven-tey merged commit 1aafd19 into main Oct 29, 2025
8 checks passed
@steven-tey steven-tey deleted the reward-e2e-tests branch October 29, 2025 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants