1.10 Test Flutter Service Layer
Sprint Key: 1-10-test-flutter-service-layer
Epic: 1
PRD: testing-framework
Story 1.10: Test Flutter Service Layer
Status: ready-for-dev
Story
As a developer, I want unit tests for the untested Flutter service-layer classes, so that business logic in the mobile app is validated independently of UI, network, and platform dependencies.
Acceptance Criteria
-
AC1: UserService tests —
test/services/user_service_test.dartcovers all 6 methods (getCurrentUserInfo,getProfile,refreshUserData,updateAccountSettings,resetUserData,deleteAccount) with success (200) and error (non-200) paths.CurrentUserApiis mocked via a fake class. -
AC2: NotificationService tests —
test/services/notification_service_test.dartverifiesshow(),success(),error(),info(),warning()emit correctNotificationEventtypes on the stream, and validates message content and duration. -
AC3: I18nService tests —
test/services/i18n_service_test.dartcoverstranslate()with nested key resolution, English fallback for missing keys, argument substitution ({key}replacement),changeLanguage()with valid/invalid/same-locale cases,isRtlfor Arabic vs English, andsupportedLanguagescompleteness. -
AC4: ConnectivityService tests —
test/services/connectivity_service_test.dartcoversisOnlinegetter (hardware + override logic),toggleUserOfflineMode(),setUserOfflineMode(),recheckConnectivity()with DNS fallback, and stream emission.Connectivityplugin andInternetAddress.lookupare mocked. -
AC5: GenieAiConfig tests —
test/services/genie_ai_config_test.dartcoversload()parsing JSON config (title + icon path), idempotent loading (_loadedguard), and default values when config is malformed.rootBundleis mocked viaTestWidgetsFlutterBinding. -
AC6: Shared test fixtures —
test/fixtures/tokens.dartexports JWT token fixture factories.test/fixtures/api_responses.dartexports mock API response factories for user profile, account settings, and common backend responses. -
AC7: CI compatibility — All tests pass
flutter test, produce JUnit XML viatojunit, and passflutter analyzewithout warnings. No new dependencies are added topubspec.yaml. -
AC8: Test count — At least 40 new tests across all test files, covering happy paths, error paths, and edge cases.