Unit Test Credential Validator
epic-email-password-login-foundation-task-009 — Write comprehensive unit tests for CredentialValidator covering valid emails, malformed emails (missing @, missing domain, consecutive dots), valid passwords, and passwords failing each individual constraint rule. Achieve 100% branch coverage. Tests must run without network access and complete in under 500ms.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 2 - 518 tasks
Can start after Tier 1 completes
Implementation Notes
Use table-driven tests: define a list of (input, expectedResult) records and iterate with test() inside forEach. This makes adding new edge cases trivial and keeps the file concise. For email tests, ensure the regex or validation logic is tested through the public API only — do not test internal regex strings directly, as that creates brittle coupling. For password constraint tests, name each test after the specific constraint being violated (e.g., 'returns invalid when password has no digit') so failures are immediately actionable in CI logs.
If CredentialValidator is a static class, no setup/teardown is needed.
Testing Requirements
Pure unit tests using flutter_test. Organise tests with nested group() blocks: one group for validateEmail and one for validatePassword, with sub-groups for valid cases and each category of invalid case. Use parameterised test helpers (e.g., a local testCases list with forEach) to avoid repetitive test boilerplate for similar invalid-input scenarios. Run flutter test --coverage and confirm credential_validator.dart shows 100% line and branch coverage before marking the task complete.
Supabase client initialization may fail silently in certain Flutter environments if environment variables are missing or the anon key is rotated, leading to runtime null-pointer errors throughout the auth layer.
Mitigation & Contingency
Mitigation: Add explicit assertion checks during app startup that verify the Supabase client is initialized before the router resolves. Document required --dart-define keys in the project README and add a CI step that validates their presence.
Contingency: Implement a fallback initialization error screen with a clear message and a retry button. Log initialization failures to crash reporting immediately.
The flutter_secure_storage package behaviour differs between iOS Keychain and Android Keystore implementations. On Android, biometric-enrolled devices may require additional authentication to read stored tokens, causing unexpected session read failures.
Mitigation & Contingency
Mitigation: Test the repository on Android devices with and without biometric enrollment early in development. Use accessibility options in flutter_secure_storage to configure whether biometric authentication is required for storage access.
Contingency: If biometric-gated storage causes regressions, fall back to a non-biometric storage option for session tokens (reserving biometric-gated storage for higher-sensitivity credentials only).