@@ -11,17 +11,26 @@ function referralRow(params: {
1111 qualified : boolean ;
1212 disqualificationReason : string | null ;
1313 impactReportState : string ;
14+ product ?: 'kiloclaw' | 'kilo_pass' ;
15+ rewardStatus ?: string ;
1416} ) {
17+ const product = params . product ?? 'kiloclaw' ;
18+ const productLabel = product === 'kilo_pass' ? 'Kilo Pass' : 'KiloClaw' ;
19+
1520 return {
1621 referral : {
1722 id : params . referralId ,
23+ product,
24+ productLabel,
1825 impactReferralId : 'RS-SUPPORT' ,
1926 createdAt : '2026-04-01T00:00:00.000Z' ,
2027 } ,
2128 referee : { id : `${ params . referralId } -referee` , email : params . refereeEmail , name : null } ,
2229 sourceTouch : null ,
2330 conversion : {
2431 id : `${ params . referralId } -conversion` ,
32+ product,
33+ paymentProvider : product === 'kilo_pass' ? 'stripe' : 'credits' ,
2534 winningTouchType : 'referral' ,
2635 sourcePaymentId : params . paymentId ,
2736 qualified : params . qualified ,
@@ -33,21 +42,52 @@ function referralRow(params: {
3342 id : `${ params . referralId } -decision` ,
3443 beneficiaryUserId : 'referrer-1' ,
3544 beneficiaryRole : 'referrer' ,
45+ product,
3646 outcome : params . qualified ? 'granted' : 'disqualified' ,
3747 reason : params . disqualificationReason ,
38- monthsGranted : params . qualified ? 1 : 0 ,
48+ rewardKind : product === 'kilo_pass' ? 'kilo_pass_bonus' : 'kiloclaw_free_month' ,
49+ monthsGranted : product === 'kiloclaw' && params . qualified ? 1 : 0 ,
50+ rewardPercent : product === 'kilo_pass' ? 0.5 : null ,
51+ sourceTier : product === 'kilo_pass' ? 'tier_49' : null ,
52+ rewardAmountUsd : product === 'kilo_pass' && params . qualified ? 24.5 : null ,
3953 createdAt : '2026-04-10T00:00:00.000Z' ,
4054 } ,
4155 ] ,
42- rewards : [ ] ,
56+ rewards : params . qualified
57+ ? [
58+ {
59+ id : `${ params . referralId } -reward` ,
60+ product,
61+ beneficiaryUserId : 'referrer-1' ,
62+ beneficiaryRole : 'referrer' ,
63+ rewardKind : product === 'kilo_pass' ? 'kilo_pass_bonus' : 'kiloclaw_free_month' ,
64+ status : params . rewardStatus ?? 'applied' ,
65+ monthsGranted : product === 'kiloclaw' ? 1 : 0 ,
66+ rewardPercent : product === 'kilo_pass' ? 0.5 : null ,
67+ sourceTier : product === 'kilo_pass' ? 'tier_49' : null ,
68+ rewardAmountUsd : product === 'kilo_pass' ? 24.5 : null ,
69+ earnedAt : '2026-04-10T00:00:00.000Z' ,
70+ appliedAt : params . rewardStatus === 'pending' ? null : '2026-04-10T00:05:00.000Z' ,
71+ expiresAt : '2027-04-10T00:00:00.000Z' ,
72+ reviewReason :
73+ params . rewardStatus === 'review_required' ? 'referral_payment_chargeback' : null ,
74+ appliesToKiloPassSubscriptionId : null ,
75+ consumedKiloPassIssuanceId : null ,
76+ consumedKiloPassIssuanceItemId : null ,
77+ } ,
78+ ]
79+ : [ ] ,
4380 rewardApplications : params . qualified
4481 ? [
4582 {
4683 id : `${ params . referralId } -application` ,
4784 beneficiaryUserId : 'referrer-1' ,
4885 subscriptionId : '55555555-5555-4555-8555-555555555555' ,
4986 previousRenewalBoundary : '2026-05-01T12:00:00.000Z' ,
87+ product,
5088 newRenewalBoundary : '2026-06-01T12:00:00.000Z' ,
89+ localOperationId : null ,
90+ stripeOperationId : null ,
5191 appliedAt : '2026-04-10T00:05:00.000Z' ,
5292 } ,
5393 ]
@@ -63,11 +103,32 @@ function referralRow(params: {
63103 responseStatusCode : params . impactReportState === 'failed' ? 400 : null ,
64104 } ,
65105 ] ,
106+ impactRewardRedemptions : [ ] ,
66107 } ;
67108}
68109
69110const result = {
111+ product : 'kiloclaw' as const ,
112+ productLabel : 'KiloClaw' ,
70113 referrer : { id : 'referrer-1' , email : 'referrer@example.com' , name : 'Referrer' } ,
114+ participantRegistrations : [
115+ {
116+ id : '55555555-5555-4555-8555-555555555556' ,
117+ programKey : 'kiloclaw' as const ,
118+ registrationState : 'pending' ,
119+ registeredAt : null ,
120+ lastRegistrationAttemptAt : null ,
121+ lastErrorCode : null ,
122+ lastErrorMessage : null ,
123+ latestAttempt : {
124+ id : '55555555-5555-4555-8555-555555555557' ,
125+ deliveryState : 'queued' ,
126+ responseStatusCode : null ,
127+ nextRetryAt : '2026-04-11T00:00:00.000Z' ,
128+ createdAt : '2026-04-10T00:00:00.000Z' ,
129+ } ,
130+ } ,
131+ ] ,
71132 referrals : [
72133 referralRow ( {
73134 referralId : 'qualified-referral' ,
@@ -95,10 +156,14 @@ describe('KiloclawReferralsInvestigationResults', () => {
95156 ) ;
96157
97158 expect ( html ) . toContain ( 'referrer@example.com' ) ;
159+ expect ( html ) . toContain ( 'KiloClaw referrer' ) ;
160+ expect ( html ) . toContain ( 'kiloclaw: pending' ) ;
161+ expect ( html ) . toContain ( 'Latest attempt: queued' ) ;
98162 expect ( html ) . toContain ( 'Qualified' ) ;
99163 expect ( html ) . toContain ( 'Disqualified' ) ;
100164 expect ( html ) . toContain ( 'referral_self_referral' ) ;
101165 expect ( html ) . toContain ( 'granted' ) ;
166+ expect ( html ) . toContain ( 'applied, 1 month' ) ;
102167 expect ( html ) . toContain ( 'delivered, tracker 71659, order qualified-payment' ) ;
103168 expect ( html ) . toContain ( 'failed, tracker 71659, order disqualified-payment, HTTP 400' ) ;
104169 expect ( html ) . toContain ( 'May 1, 2026 to' ) ;
0 commit comments