ReceiptStorageRepository integration tests
epic-receipt-capture-and-attachment-foundation-task-007 — Write integration tests for ReceiptStorageRepository against a Supabase test environment. Cover upload of a small JPEG byte array, verify the file exists at the expected scoped path, generate a signed URL and assert it is non-empty, then delete the file and confirm 404 on subsequent signed URL generation. Use flutter_test with a dedicated test Supabase project.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
Create test file at test/integration/receipt_storage_repository_integration_test.dart. Use a package:test group() to wrap all tests so setUp/tearDown applies consistently. Generate a synthetic 5KB JPEG using a minimal valid JPEG byte sequence (FFD8FF + minimal headers + FFD9) rather than bundling a real image asset. Authenticate via Supabase Auth signInWithPassword using a dedicated test user seeded in the test project.
The hardest part is reliably asserting the 404 state after deletion — check the Supabase Storage SDK's exception type hierarchy and match on the specific error code rather than message string. Document the test Supabase project setup steps in a TESTING.md or inline comment block at the top of the test file.
Testing Requirements
Integration tests using flutter_test against a live Supabase test environment. Test scenarios: (1) upload JPEG bytes → assert path returned matches ReceiptStoragePathBuilder output, (2) sign URL → assert URL is valid HTTPS string, (3) delete → assert subsequent sign URL call fails with expected error type, (4) cross-org access attempt → assert StorageException thrown. Use setUp to create a test user session via Supabase Auth and addTearDown for cleanup. Tag tests with 'integration' so they are skipped in unit test CI steps but run in a dedicated integration test step.
Supabase Storage RLS policies using org/user/claim path scoping may not enforce correctly if claim ownership is not present in the JWT or if path segments are constructed differently at upload vs. read time, leading to data leakage or access denial for legitimate users.
Mitigation & Contingency
Mitigation: Define and test RLS policies in isolation before wiring to app code. Write integration tests that assert cross-org and cross-user access is denied. Use service-role key only in edge functions, never in client code.
Contingency: If client-side RLS proves insufficient, route all storage reads through a Supabase Edge Function that validates ownership before generating signed URLs, adding a controlled server-side enforcement layer.
Aggressive image compression may reduce receipt legibility below the threshold required for financial auditing, causing claim rejections or compliance failures despite technically successful uploads.
Mitigation & Contingency
Mitigation: Define minimum legibility requirements with HLF finance team before implementation. Set compression targets conservatively (e.g., max 1MB, min 80% JPEG quality) and validate with sample receipt images. Provide compression statistics in verbose/debug mode.
Contingency: If post-compression quality is disputed by auditors, increase the quality floor at the cost of larger file sizes, and add a manual override allowing users to skip compression for PDFs and high-quality scans.
The Flutter image_picker package behaves differently on iOS 17+ (PHPicker) vs older Android (Intent-based), particularly for file types, permission flows, and PDF selection, which may cause platform-specific failures not caught in development.
Mitigation & Contingency
Mitigation: Test image picker integration on physical devices for both platforms early in the sprint. Pin the image_picker package version and review changelogs before updates. Write widget tests using mock file results for each platform branch.
Contingency: If PHPicker or Android Intent differences cause blocking issues, implement separate platform-specific picker delegates behind the unified interface, allowing platform-specific fixes without breaking the shared API.