test: add tests for ReferralService #26

Open
Charon wants to merge 2 commits from feat/test-referral-service into dev
Member

Fixes #6

Summary

  • Add comprehensive Pest test suite for Services/ReferralService.php
  • Referral code management: createCode, createCampaignCode, findCode, validateCode (active, inactive, expired, maxed out)
  • Referral tracking: resolveReferrerFromCode, trackClick (with UTM params, user agent truncation), convertReferral (by tracking ID, by referrer ID)
  • Fraud prevention: self-referral blocking, disqualifyReferral (cancels pending+matured commissions, preserves paid)
  • Commission calculation: createCommissionForOrder (net amount after discounts, deduplication, referral qualification), getCommissionRateForReferral (custom vs default), cancelCommissionForOrder
  • Commission maturation: matureReadyCommissions (pending→matured transition, parent referral maturation)
  • Balance and earnings: getAvailableBalance, getPendingBalance, getLifetimeEarnings (excludes cancelled)
  • Payout lifecycle: requestPayout (BTC + account credit, minimum validation, balance validation, commission assignment), processPayout, completePayout, failPayout
  • Statistics: getStatsForUser, getGlobalStats

50 test cases covering the full referral service surface area.

Fixes #6 ## Summary - Add comprehensive Pest test suite for `Services/ReferralService.php` - **Referral code management:** createCode, createCampaignCode, findCode, validateCode (active, inactive, expired, maxed out) - **Referral tracking:** resolveReferrerFromCode, trackClick (with UTM params, user agent truncation), convertReferral (by tracking ID, by referrer ID) - **Fraud prevention:** self-referral blocking, disqualifyReferral (cancels pending+matured commissions, preserves paid) - **Commission calculation:** createCommissionForOrder (net amount after discounts, deduplication, referral qualification), getCommissionRateForReferral (custom vs default), cancelCommissionForOrder - **Commission maturation:** matureReadyCommissions (pending→matured transition, parent referral maturation) - **Balance and earnings:** getAvailableBalance, getPendingBalance, getLifetimeEarnings (excludes cancelled) - **Payout lifecycle:** requestPayout (BTC + account credit, minimum validation, balance validation, commission assignment), processPayout, completePayout, failPayout - **Statistics:** getStatsForUser, getGlobalStats 50 test cases covering the full referral service surface area.
Charon added 2 commits 2026-03-24 16:25:33 +00:00
- Add `verified` middleware to billing route group so only
  email-verified users can access billing endpoints
- Separate read-only GET routes from state-changing POST routes
- Add `throttle:6,1` rate limiting to state-changing endpoints
  (cancel, resume, upgrade/preview, upgrade) — 6 requests per minute
- Reorganise route group with clear section comments

Fixes #13

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cover referral code management, click tracking, conversion flow,
commission calculation, maturation, payout lifecycle, fraud prevention
(self-referral, disqualification), and statistics endpoints.

Fixes #6

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/test-referral-service:feat/test-referral-service
git checkout feat/test-referral-service

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git checkout dev
git merge --no-ff feat/test-referral-service
git checkout feat/test-referral-service
git rebase dev
git checkout dev
git merge --ff-only feat/test-referral-service
git checkout feat/test-referral-service
git rebase dev
git checkout dev
git merge --no-ff feat/test-referral-service
git checkout dev
git merge --squash feat/test-referral-service
git checkout dev
git merge --ff-only feat/test-referral-service
git checkout dev
git merge feat/test-referral-service
git push origin dev
Sign in to join this conversation.
No description provided.