Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions src/apps/reports/src/pages/reports/ReportsPage.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ import {
useLocation,
} from 'react-router-dom'

import { fetchReportsIndex } from '../../lib/services'
import {
fetchReportJson,
fetchReportsIndex,
SfdcBillingAccountPaymentRow,
} from '../../lib/services'

import { ReportsPage } from './ReportsPage'
import { BillingAccountsPage, ReportsPage } from './ReportsPage'

type MockSelectProps = {
disabled?: boolean
Expand Down Expand Up @@ -86,6 +90,8 @@ jest.mock('../../lib/utils', () => ({
}))

const mockedFetchReportsIndex = fetchReportsIndex as jest.Mock
const mockedFetchReportJson = fetchReportJson as jest.Mock
const originalTimezone = process.env.TZ

const LocationProbe = (): JSX.Element => {
const { pathname }: { pathname: string } = useLocation()
Expand All @@ -109,6 +115,15 @@ describe('Reports page navigation', () => {
})
})

afterEach(() => {
if (originalTimezone) {
process.env.TZ = originalTimezone
return
}

delete process.env.TZ
})

it('opens Bulk Member Lookup from the Reports app root', async () => {
render(
<MemoryRouter initialEntries={['/reports/reports']}>
Expand Down Expand Up @@ -137,4 +152,64 @@ describe('Reports page navigation', () => {
expect(screen.getByTestId('location'))
.toHaveTextContent('/reports/bulk-member-lookup')
})

it('renders SFDC payment dates in America/New_York', async () => {
process.env.TZ = 'Asia/Colombo'
const paymentDate = '2026-07-31T18:53:33.383-04:00'
const payment: SfdcBillingAccountPaymentRow = {
billingAccountId: '80000001',
category: 'CHALLENGE_PAYMENT',
challengeFee: '0.00',
challengeId: 'challenge-id',
challengeName: 'July payment',
challengeStatus: 'Completed',
isTask: false,
paymentAmount: '100.00',
paymentDate,
paymentId: 'payment-id',
paymentStatus: 'PAID',
winnerFirstName: 'Ada',
winnerHandle: 'ada',
winnerId: '123',
winnerLastName: 'Lovelace',
}
mockedFetchReportJson.mockResolvedValue([payment])

render(
<MemoryRouter initialEntries={['/reports/sfdc-payments']}>
<BillingAccountsPage />
</MemoryRouter>,
)

expect(await screen.findByText('July payment'))
.toBeInTheDocument()
const parsedPaymentDate = new Date(paymentDate)
const displayedDate = parsedPaymentDate
.toLocaleString(undefined, { timeZone: 'America/New_York' })
const browserDisplayedDate = parsedPaymentDate
.toLocaleString()

expect(screen.getByText(displayedDate))
.toBeInTheDocument()
expect(parsedPaymentDate.getUTCDate())
.toBe(31)
expect(parsedPaymentDate.getDate())
.toBe(1)
expect(displayedDate)
.not.toBe(browserDisplayedDate)

mockedFetchReportJson.mockResolvedValueOnce({
billingAccount: {
budget: '1000.00',
markup: '0.00',
name: 'Boundary account',
startDate: paymentDate,
status: 'Active',
},
})
fireEvent.click(screen.getByRole('button', { name: '80000001' }))

expect(await screen.findByText(browserDisplayedDate))
.toBeInTheDocument()
})
})
18 changes: 17 additions & 1 deletion src/apps/reports/src/pages/reports/ReportsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ const formatPaymentDate = (iso: string): string => {
.toLocaleString()
}

/**
* Formats an SFDC payment timestamp in the report's America/New_York timezone.
* The input is an ISO date-time string and the returned value is used in payment table cells.
* Invalid inputs are returned unchanged, so this function does not throw parsing errors.
*/
const formatSfdcPaymentDate = (iso: string): string => {
const parsed = Date.parse(iso)

if (Number.isNaN(parsed)) {
return iso
}

return new Date(parsed)
.toLocaleString(undefined, { timeZone: 'America/New_York' })
}

const PAYMENT_TABLE_COLUMNS: { key: keyof SfdcBillingAccountPaymentRow; label: string }[] = [
{ key: 'paymentId', label: 'Payment ID' },
{ key: 'paymentDate', label: 'Payment date' },
Expand Down Expand Up @@ -431,7 +447,7 @@ const BillingAccountReportResults = (
const value = row[colKey]

if (colKey === 'paymentDate') {
return formatPaymentDate(String(value))
return formatSfdcPaymentDate(String(value))
}

if (colKey === 'billingAccountId') {
Expand Down
Loading