Skip to content

Commit abd04a7

Browse files
fix(referrals): redeem Impact month rewards (#3498)
1 parent b73a61c commit abd04a7

4 files changed

Lines changed: 67 additions & 7 deletions

File tree

apps/web/src/lib/impact/advocate.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ describe('impact advocate', () => {
190190
const result = await sendImpactAdvocateRewardRedemptionPayload({
191191
rewardId: 'reward-123',
192192
amount: 1,
193-
unit: 'free-months',
193+
unit: 'MONTH',
194194
});
195195

196196
expect(result).toEqual({ ok: true, statusCode: 200, responseBody: '{"ok":true}' });
@@ -205,7 +205,7 @@ describe('impact advocate', () => {
205205
Accept: 'application/json',
206206
'Content-Type': 'application/json',
207207
}),
208-
body: '{"amount":1,"unit":"free-months"}',
208+
body: '{"amount":1,"unit":"MONTH"}',
209209
});
210210
});
211211

apps/web/src/lib/impact/kiloclaw-referrals.test.ts

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

apps/web/src/lib/impact/kiloclaw-referrals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const REFERRAL_REWARD_ACTOR = {
126126
} as const;
127127

128128
const SIGNUP_REFERRAL_TOUCH_CAPTURE_GRACE_MS = 10 * 60 * 1000;
129-
const IMPACT_ADVOCATE_REWARD_UNIT = 'free-months';
129+
const IMPACT_ADVOCATE_REWARD_UNIT = 'MONTH';
130130

131131
function getDatabaseClient(database?: DatabaseClient): DatabaseClient {
132132
return database ?? db;

apps/web/src/lib/user/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ describe('User', () => {
729729
userId: user.google_user_email,
730730
rewardTypeFilter: 'CREDIT',
731731
},
732-
redemption: { amount: 1, unit: 'free-months' },
732+
redemption: { amount: 1, unit: 'MONTH' },
733733
},
734734
});
735735
await db.insert(impact_conversion_reports).values({

0 commit comments

Comments
 (0)