-
Notifications
You must be signed in to change notification settings - Fork 14
feat(badges): consume declarative acquisition platform #2613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
0xkkonrad
wants to merge
1
commit into
main
Choose a base branch
from
codex/badge-platform-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import { validateInviteCode } from '../invites' | ||
| import { serverFetch } from '@/utils/api-fetch' | ||
|
|
||
| jest.mock('@/utils/api-fetch', () => ({ serverFetch: jest.fn() })) | ||
|
|
||
| const mockServerFetch = serverFetch as jest.MockedFunction<typeof serverFetch> | ||
|
|
||
| function response(status: number, body: unknown): Response { | ||
| return { | ||
| ok: status >= 200 && status < 300, | ||
| status, | ||
| json: jest.fn().mockResolvedValue(body), | ||
| } as unknown as Response | ||
| } | ||
|
|
||
| describe('validateInviteCode mixed-version resolution', () => { | ||
| beforeEach(() => jest.clearAllMocks()) | ||
|
|
||
| it('treats a typed campaign-only HTTP 409 as a settled transport result', async () => { | ||
| mockServerFetch.mockResolvedValue( | ||
| response(409, { | ||
| message: 'Campaign processed without invite attribution', | ||
| attributionResolved: false, | ||
| onboardingResolved: false, | ||
| username: '', | ||
| legacyAcquisition: { | ||
| campaignTag: 'offramp', | ||
| fallback: 'normal_app', | ||
| destination: 'offramp_migration', | ||
| }, | ||
| }) | ||
| ) | ||
|
|
||
| await expect(validateInviteCode('offramp')).resolves.toEqual({ | ||
| data: { | ||
| success: true, | ||
| attributionResolved: false, | ||
| onboardingResolved: false, | ||
| username: '', | ||
| legacyAcquisition: { | ||
| campaignTag: 'offramp', | ||
| fallback: 'normal_app', | ||
| destination: 'offramp_migration', | ||
| }, | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| it('keeps an untyped HTTP 409 as a transport failure', async () => { | ||
| mockServerFetch.mockResolvedValue(response(409, { error: 'Invite code is not valid' })) | ||
|
|
||
| await expect(validateInviteCode('not-an-invite')).resolves.toEqual({ | ||
| error: 'Invite code is not valid', | ||
| }) | ||
| }) | ||
|
|
||
| it('supports a pre-discriminator HTTP 200 validation response with a username', async () => { | ||
| mockServerFetch.mockResolvedValue(response(200, { username: 'legacy-inviter' })) | ||
|
|
||
| await expect(validateInviteCode('legacy-invite')).resolves.toEqual({ | ||
| data: { | ||
| success: true, | ||
| attributionResolved: true, | ||
| onboardingResolved: true, | ||
| username: 'legacy-inviter', | ||
| legacyAcquisition: undefined, | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| it('lets an explicit false discriminator override the legacy username signal', async () => { | ||
| mockServerFetch.mockResolvedValue( | ||
| response(200, { | ||
| username: 'legacy-inviter', | ||
| attributionResolved: false, | ||
| onboardingResolved: false, | ||
| }) | ||
| ) | ||
|
|
||
| await expect(validateInviteCode('legacy-invite')).resolves.toMatchObject({ | ||
| data: { | ||
| success: true, | ||
| attributionResolved: false, | ||
| onboardingResolved: false, | ||
| username: 'legacy-inviter', | ||
| }, | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { getRedirectUrl } from '@/utils/general.utils' | ||
| import { | ||
| destinationForShhhhhClaims, | ||
| queueShhhhhCampaignContinuation, | ||
| settleShhhhhCampaignContinuation, | ||
| shhhhhCampaignSignupRoute, | ||
| } from './shhhhh-acquisition' | ||
|
|
||
| describe('Shhhhh campaign continuation', () => { | ||
| beforeEach(() => localStorage.clear()) | ||
|
|
||
| it.each(['awarded', 'already_owned'] as const)('continues a confirmed Skip Pass %s to /card', (outcome) => { | ||
| expect(destinationForShhhhhClaims([{ badgeCampaign: 'skip', badgeCode: 'WAITLIST_SKIP', outcome }])).toBe( | ||
| '/card' | ||
| ) | ||
| }) | ||
|
|
||
| it.each(['inactive', 'expired', 'unknown', 'definition_missing', 'retryable_error'] as const)( | ||
| 'falls back home for %s', | ||
| (outcome) => { | ||
| expect(destinationForShhhhhClaims([{ badgeCampaign: 'skip', badgeCode: 'WAITLIST_SKIP', outcome }])).toBe( | ||
| '/home' | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| it('does not treat an unrelated confirmed badge as a card continuation', () => { | ||
| expect( | ||
| destinationForShhhhhClaims([{ badgeCampaign: 'event', badgeCode: 'EVENT_ALUMNI', outcome: 'awarded' }]) | ||
| ).toBe('/home') | ||
| }) | ||
|
|
||
| it('starts signed-out registration without an unconditional card redirect', () => { | ||
| expect(shhhhhCampaignSignupRoute()).toBe('/setup?step=signup') | ||
| }) | ||
|
|
||
| it.each(['awarded', 'already_owned'] as const)( | ||
| 'replaces the safe signed-out marker with /card after confirmed Skip Pass %s', | ||
| (outcome) => { | ||
| queueShhhhhCampaignContinuation() | ||
| expect( | ||
| settleShhhhhCampaignContinuation([{ badgeCampaign: 'skip', badgeCode: 'WAITLIST_SKIP', outcome }]) | ||
| ).toBe('/card') | ||
| expect(getRedirectUrl()).toBe('/card') | ||
| } | ||
| ) | ||
|
|
||
| it.each(['inactive', 'expired', 'unknown', 'definition_missing', 'retryable_error'] as const)( | ||
| 'keeps the signed-out continuation on the normal app after %s', | ||
| (outcome) => { | ||
| queueShhhhhCampaignContinuation() | ||
| expect( | ||
| settleShhhhhCampaignContinuation([{ badgeCampaign: 'skip', badgeCode: 'WAITLIST_SKIP', outcome }]) | ||
| ).toBe('/home') | ||
| expect(getRedirectUrl()).toBe('/home') | ||
| } | ||
| ) | ||
|
|
||
| it("does not consume another acquisition flow's stored destination", () => { | ||
| localStorage.setItem('redirect', JSON.stringify('/claim?step=claim')) | ||
| expect( | ||
| settleShhhhhCampaignContinuation([ | ||
| { badgeCampaign: 'skip', badgeCode: 'WAITLIST_SKIP', outcome: 'awarded' }, | ||
| ]) | ||
| ).toBeUndefined() | ||
| expect(getRedirectUrl()).toBe('/claim?step=claim') | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Set the busy state around the campaign claim.
The campaign branch performs an async claim, a user refresh, and a navigation, but it never sets
ctaBusy. OnlyjoinWaitlist()sets it. All three CTAs stay enabled during the request, so a user can click again and start a secondclaimAndSettlePendingBadgeCampaignscall, a secondfetchUser(), and a racingrouter.push. The user also gets no feedback while the claim is in flight.Wrap the campaign branch in the same busy state that
joinWaitlistuses.🛠️ Proposed fix
if (badgeCampaigns.length > 0) { const queuedBadgeCampaigns = queuePendingBadgeCampaigns(badgeCampaigns, 30) if (!user) { queueShhhhhCampaignContinuation() router.push(shhhhhCampaignSignupRoute()) return } let destination: '/card' | '/home' = '/home' + setCtaBusy(true) try { const batch = await claimAndSettlePendingBadgeCampaigns(queuedBadgeCampaigns) @@ } catch (error) { captureException(error, { tags: { error_type: 'campaign_claim_unexpected_failure' } }) + } finally { + setCtaBusy(false) }📝 Committable suggestion
🤖 Prompt for AI Agents