Skip to content

Open-source personal finance manager. Self-hosted, privacy-first.

fix: allow receipt uploads over plain HTTP (#982)

Andrew Barnese87e7fce8c9a
diff --git a/frontend/src/components/transaction-attachments.test.tsx b/frontend/src/components/transaction-attachments.test.tsx
new file mode 100644
index 00000000..68439b67
--- /dev/null
+++ b/frontend/src/components/transaction-attachments.test.tsx
@@ -0,0 +1,72 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { act, screen, waitFor } from '@testing-library/react'
+
+import { TransactionAttachments } from '@/components/transaction-attachments'
+import { transactions, settings } from '@/lib/api'
+import { renderWithProviders, t } from '@/test/utils'
+import type { Attachment } from '@/types'
+
+vi.mock('@/hooks/use-display-locale', () => ({ useDateLocale: () => 'en-US' }))
+
+vi.mock('@/lib/api', () => ({
+ transactions: {
+ attachments: {
+ list: vi.fn(),
+ upload: vi.fn(),
+ },
+ },
+ settings: { attachments: vi.fn() },
+}))
+
+describe('TransactionAttachments on HTTP', () => {
+ beforeEach(() => {
+ vi.stubGlobal('crypto', { randomUUID: undefined })
+ vi.mocked(transactions.attachments.list).mockResolvedValue([])
+ vi.mocked(settings.attachments).mockResolvedValue({
+ allowed_extensions: ['pdf'],
+ max_file_size_mb: 10,
+ max_attachments_per_transaction: 10,
+ })
+ })
+
+ afterEach(() => {
+ vi.unstubAllGlobals()
+ vi.resetAllMocks()
+ })
+
+ it('uploads multiple receipts and removes only the completed placeholder', async () => {
+ const pending: Array<() => void> = []
+ vi.mocked(transactions.attachments.upload).mockImplementation((transactionId, file) =>
+ new Promise<Attachment>(resolve => {
+ pending.push(() => resolve({
+ id: file.name,
+ transaction_id: transactionId,
+ filename: file.name,
+ content_type: file.type,
+ size: file.size,
+ created_at: '2026-01-01T00:00:00Z',
+ }))
+ }),
+ )
+ const { container, user } = renderWithProviders(
+ <TransactionAttachments transactionId="transaction-1" />,
+ )
+ await screen.findByText(t('transactions.attachmentsUpload'))
+ const first = new File(['first'], 'first.pdf', { type: 'application/pdf' })
+ const second = new File(['second'], 'second.pdf', { type: 'application/pdf' })
+
+ await user.upload(container.querySelector('input[type="file"]')!, [first, second])
+
+ await waitFor(() => expect(transactions.attachments.upload).toHaveBeenCalledTimes(2))
+ expect(transactions.attachments.upload).toHaveBeenCalledWith('transaction-1', first)
+ expect(transactions.attachments.upload).toHaveBeenCalledWith('transaction-1', second)
+ expect(screen.getByText('first.pdf')).toBeInTheDocument()
+ expect(screen.getByText('second.pdf')).toBeInTheDocument()
+
+ await act(async () => { pending[0]() })
+ await waitFor(() => expect(screen.queryByText('first.pdf')).not.toBeInTheDocument())
+ expect(screen.getByText('second.pdf')).toBeInTheDocument()
+ await act(async () => { pending[1]() })
+ await waitFor(() => expect(screen.queryByText('second.pdf')).not.toBeInTheDocument())
+ })
+})
diff --git a/frontend/src/components/transaction-attachments.tsx b/frontend/src/components/transaction-attachments.tsx
index 1c78eea8..6f4b633e 100644
--- a/frontend/src/components/transaction-attachments.tsx
+++ b/frontend/src/components/transaction-attachments.tsx
@@ -61,6 +61,7 @@ export function TransactionAttachments({
const { t } = useTranslation()
const queryClient = useQueryClient()
const fileInputRef = useRef<HTMLInputElement>(null)
+ const nextUploadId = useRef(0)
const lastClickedRef = useRef<string | null>(null)
const [dragOver, setDragOver] = useState(false)
const [deletingId, setDeletingId] = useState<string | null>(null)
@@ -280,7 +281,7 @@ export function TransactionAttachments({
toast.error(t('transactions.attachmentTooLarge'))
continue
}
- const optimisticId = `optimistic-${crypto.randomUUID()}`
+ const optimisticId = `optimistic-${nextUploadId.current++}`
uploadMutation.mutate({ file, optimisticId })
uploaded++
}