-
Notifications
You must be signed in to change notification settings - Fork 14
fix(card): don't render "#null" for a waitlist entry without a position #2437
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
9aad003
fix(card): don't render '#null' for a waitlist entry without a position
innolope-dev 3b8466e
test(card): derive the expected waitlist position from the active locale
innolope-dev 877b2f9
Merge remote-tracking branch 'origin/main' into fix/physical-waitlist…
innolope-dev 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * PhysicalCardScreen — waitlist "on the list" copy contract. | ||
| * | ||
| * The joined branch is gated on joinedAt, but the API types position as | ||
| * nullable, so a joined user can have no queue position. Interpolating it | ||
| * blindly renders "You are #null on the list." | ||
| */ | ||
| import React from 'react' | ||
| import { render, screen } from '@testing-library/react' | ||
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
| import PhysicalCardScreen from '@/components/Card/PhysicalCardScreen' | ||
| import { rainApi } from '@/services/rain' | ||
|
|
||
| jest.mock('@/context/authContext', () => ({ | ||
| useAuth: () => ({ user: { accounts: [] }, fetchUser: jest.fn() }), | ||
| })) | ||
| jest.mock('next/image', () => ({ | ||
| __esModule: true, | ||
| // eslint-disable-next-line @next/next/no-img-element -- test stub, not real markup | ||
| default: (props: Record<string, unknown>) => <img alt={String(props.alt ?? '')} />, | ||
| })) | ||
| jest.mock('posthog-js', () => ({ __esModule: true, default: { capture: jest.fn() } })) | ||
| jest.mock('@/services/rain', () => ({ | ||
| rainApi: { getPhysicalWaitlist: jest.fn(), joinPhysicalWaitlist: jest.fn() }, | ||
| })) | ||
|
|
||
| const mockGet = rainApi.getPhysicalWaitlist as jest.Mock | ||
|
|
||
| const renderScreen = () => { | ||
| const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } }) | ||
| return render( | ||
| <QueryClientProvider client={queryClient}> | ||
| <PhysicalCardScreen cardId="card-1" last4="4242" /> | ||
| </QueryClientProvider> | ||
| ) | ||
| } | ||
|
|
||
| describe('PhysicalCardScreen — joined waitlist copy', () => { | ||
| beforeEach(() => jest.clearAllMocks()) | ||
|
|
||
| it('shows the queue position when the API returns one', async () => { | ||
| mockGet.mockResolvedValue({ joinedAt: '2026-01-01T00:00:00Z', position: 42 }) | ||
| renderScreen() | ||
| expect(await screen.findByText(/You are #42 on the list\./)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('omits the position rather than rendering "#null" when there is none', async () => { | ||
| mockGet.mockResolvedValue({ joinedAt: '2026-01-01T00:00:00Z', position: null }) | ||
| renderScreen() | ||
| const body = await screen.findByText(/You are on the list\./) | ||
| expect(body).toBeInTheDocument() | ||
| expect(body.textContent).not.toMatch(/#/) | ||
| }) | ||
|
|
||
| // Derived rather than hardcoded: the separator is locale-dependent, and the | ||
| // contract is that the copy delegates to toLocaleString, not that it says "1,234". | ||
| it('formats large positions with thousands separators', async () => { | ||
| mockGet.mockResolvedValue({ joinedAt: '2026-01-01T00:00:00Z', position: 1234 }) | ||
| renderScreen() | ||
| const body = await screen.findByText(/on the list\./) | ||
| expect(body.textContent).toContain(`You are #${(1234).toLocaleString()} on the list.`) | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }) | ||
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
Use a loose equality check to prevent runtime crashes if
positionisundefined.The strict equality check (
=== null) will evaluate tofalseif the API omits thepositionfield, makingdata.positionundefined. This would cause the app to crash with aTypeError: Cannot read properties of undefined (reading 'toLocaleString').Using a loose equality check (
== null) handles bothnullandundefinedsafely.🛡️ Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents