@@ -270,7 +270,7 @@ describe('kiloclaw referrals', () => {
270270 userId : user . google_user_email ,
271271 rewardTypeFilter : 'CREDIT' ,
272272 } ,
273- redemption : { amount : 1 , unit : 'free-months ' } ,
273+ redemption : { amount : 1 , unit : 'MONTH ' } ,
274274 } ,
275275 } ) ;
276276 mockSendImpactAdvocateRewardRedemptionPayload . mockResolvedValueOnce ( {
@@ -311,7 +311,7 @@ describe('kiloclaw referrals', () => {
311311 userId : user . google_user_email ,
312312 rewardTypeFilter : 'CREDIT' ,
313313 } ,
314- redemption : { amount : 1 , unit : 'free-months ' } ,
314+ redemption : { amount : 1 , unit : 'MONTH ' } ,
315315 } ,
316316 } ) ;
317317 mockSendImpactAdvocateRewardRedemptionPayload . mockResolvedValueOnce ( {
@@ -334,6 +334,66 @@ describe('kiloclaw referrals', () => {
334334 } )
335335 ) ;
336336 } ) ;
337+
338+ it ( 'redeems month credits returned by Impact' , async ( ) => {
339+ const user = await insertTestUser ( {
340+ google_user_email : 'month-credit@example.com' ,
341+ normalized_email : 'month-credit@example.com' ,
342+ } ) ;
343+ const rewardId = await insertAppliedReferralRewardForUser ( user . id ) ;
344+ await db . insert ( impact_advocate_reward_redemptions ) . values ( {
345+ reward_id : rewardId ,
346+ dedupe_key : `month-credit:${ rewardId } ` ,
347+ beneficiary_user_id : user . id ,
348+ state : 'queued' ,
349+ request_payload : {
350+ lookup : {
351+ accountId : user . google_user_email ,
352+ userId : user . google_user_email ,
353+ rewardTypeFilter : 'CREDIT' ,
354+ } ,
355+ redemption : { amount : 1 , unit : 'MONTH' } ,
356+ } ,
357+ } ) ;
358+ mockSendImpactAdvocateRewardLookupPayload . mockResolvedValueOnce ( {
359+ ok : true ,
360+ statusCode : 200 ,
361+ responseBody : JSON . stringify ( [
362+ {
363+ id : 'impact-month-reward' ,
364+ type : 'CREDIT' ,
365+ unit : 'MONTH' ,
366+ assignedCredit : 1 ,
367+ redeemedCredit : 0 ,
368+ } ,
369+ ] ) ,
370+ rewards : [
371+ {
372+ id : 'impact-month-reward' ,
373+ type : 'CREDIT' ,
374+ unit : 'MONTH' ,
375+ assignedCredit : 1 ,
376+ redeemedCredit : 0 ,
377+ } ,
378+ ] ,
379+ } ) ;
380+
381+ const summary = await dispatchQueuedImpactAdvocateRewardRedemptions ( ) ;
382+
383+ expect ( summary ) . toEqual ( { claimed : 1 , redeemed : 1 , retried : 0 , failed : 0 } ) ;
384+ expect ( mockSendImpactAdvocateRewardRedemptionPayload ) . toHaveBeenCalledWith ( {
385+ rewardId : 'impact-month-reward' ,
386+ amount : 1 ,
387+ unit : 'MONTH' ,
388+ } ) ;
389+ const [ redemption ] = await db . select ( ) . from ( impact_advocate_reward_redemptions ) ;
390+ expect ( redemption ) . toEqual (
391+ expect . objectContaining ( {
392+ state : 'redeemed' ,
393+ impact_reward_id : 'impact-month-reward' ,
394+ } )
395+ ) ;
396+ } ) ;
337397 } ) ;
338398
339399 describe ( 'resolveWinningAttributionTouch' , ( ) => {
@@ -1439,7 +1499,7 @@ describe('kiloclaw referrals', () => {
14391499 expect ( mockSendImpactAdvocateRewardRedemptionPayload ) . toHaveBeenCalledWith ( {
14401500 rewardId : 'impact-reward-123' ,
14411501 amount : 1 ,
1442- unit : 'free-months ' ,
1502+ unit : 'MONTH ' ,
14431503 } ) ;
14441504
14451505 const redeemedRedemptions = await db . select ( ) . from ( impact_advocate_reward_redemptions ) ;
0 commit comments