From bf6747153f5a5dec3133389757e9929b7282ebf6 Mon Sep 17 00:00:00 2001 From: Vincent Velociter Date: Thu, 3 Oct 2024 18:50:12 +0200 Subject: [PATCH] Move socket and http to network folder --- lib/src/app.dart | 29 ++++++--- lib/src/binding.dart | 2 +- lib/src/init.dart | 2 +- .../model/account/account_preferences.dart | 2 +- lib/src/model/account/account_repository.dart | 2 +- .../analysis/server_analysis_service.dart | 4 +- lib/src/model/auth/auth_controller.dart | 4 +- lib/src/model/auth/auth_repository.dart | 2 +- .../model/broadcast/broadcast_providers.dart | 2 +- .../model/broadcast/broadcast_repository.dart | 2 +- .../broadcast/broadcast_round_controller.dart | 4 +- .../model/challenge/challenge_repository.dart | 2 +- .../model/challenge/challenge_service.dart | 2 +- .../correspondence_service.dart | 4 +- lib/src/model/game/chat_controller.dart | 2 +- lib/src/model/game/game.dart | 2 +- lib/src/model/game/game_controller.dart | 4 +- lib/src/model/game/game_history.dart | 2 +- lib/src/model/game/game_repository.dart | 2 +- .../model/game/game_repository_providers.dart | 2 +- lib/src/model/game/game_share_service.dart | 2 +- lib/src/model/lobby/create_game_service.dart | 4 +- lib/src/model/lobby/lobby_numbers.dart | 2 +- lib/src/model/lobby/lobby_repository.dart | 2 +- .../notifications/notification_service.dart | 2 +- .../opening_explorer_repository.dart | 2 +- lib/src/model/puzzle/puzzle_activity.dart | 2 +- lib/src/model/puzzle/puzzle_controller.dart | 2 +- lib/src/model/puzzle/puzzle_providers.dart | 2 +- lib/src/model/puzzle/puzzle_repository.dart | 2 +- lib/src/model/puzzle/puzzle_service.dart | 2 +- lib/src/model/puzzle/storm_controller.dart | 2 +- lib/src/model/relation/online_friends.dart | 2 +- .../model/relation/relation_repository.dart | 2 +- .../relation_repository_providers.dart | 2 +- lib/src/model/study/study_repository.dart | 2 +- lib/src/model/tv/live_tv_channels.dart | 4 +- lib/src/model/tv/tv_controller.dart | 4 +- lib/src/model/tv/tv_repository.dart | 2 +- lib/src/model/user/user_repository.dart | 2 +- .../model/user/user_repository_providers.dart | 2 +- lib/src/{model/common => network}/http.dart | 28 ++++++-- lib/src/{model/common => network}/socket.dart | 2 +- lib/src/utils/connectivity.dart | 2 +- lib/src/view/account/edit_profile_screen.dart | 2 +- lib/src/view/analysis/analysis_screen.dart | 2 +- .../broadcast/broadcast_round_screen.dart | 2 +- lib/src/view/game/archived_game_screen.dart | 2 +- lib/src/view/game/game_common_widgets.dart | 2 +- lib/src/view/game/game_list_tile.dart | 2 +- lib/src/view/game/game_screen.dart | 2 +- lib/src/view/game/ping_rating.dart | 2 +- .../view/play/create_custom_game_screen.dart | 2 +- lib/src/view/play/online_bots_screen.dart | 2 +- lib/src/view/puzzle/puzzle_screen.dart | 2 +- lib/src/view/puzzle/streak_screen.dart | 2 +- lib/src/view/relation/following_screen.dart | 2 +- lib/src/view/user/perf_stats_screen.dart | 2 +- lib/src/view/user/user_activity.dart | 2 +- lib/src/view/user/user_screen.dart | 2 +- lib/src/view/watch/watch_tab_screen.dart | 2 +- test/app_test.dart | 59 ++++++++++++++++- test/mock_server_responses.dart | 40 ++++++++++++ .../account/account_repository_test.dart | 2 +- test/model/auth/auth_controller_test.dart | 64 ++++--------------- .../broadcast/broadcast_repository_test.dart | 2 +- .../challenge/challenge_repository_test.dart | 2 +- .../challenge/challenge_service_test.dart | 4 +- test/model/game/game_repository_test.dart | 2 +- test/model/lobby/lobby_repository_test.dart | 2 +- .../notification_service_test.dart | 3 +- .../opening_explorer_repository_test.dart | 2 +- test/model/puzzle/puzzle_repository_test.dart | 2 +- test/model/puzzle/puzzle_service_test.dart | 4 +- .../relation/relation_repository_test.dart | 2 +- test/model/user/user_repository_test.dart | 2 +- .../fake_websocket_channel.dart | 2 +- .../common => network}/socket_test.dart | 2 +- test/test_container.dart | 6 +- test/test_provider_scope.dart | 12 ++-- test/view/analysis/analysis_screen_test.dart | 4 +- .../board_editor_screen_test.dart | 20 +++--- .../broadcasts_list_screen_test.dart | 6 +- .../coordinate_training_screen_test.dart | 6 +- test/view/game/archived_game_screen_test.dart | 8 +-- .../opening_explorer_screen_test.dart | 8 +-- .../over_the_board_screen_test.dart | 2 +- test/view/puzzle/puzzle_screen_test.dart | 14 ++-- test/view/puzzle/storm_screen_test.dart | 12 ++-- .../settings/settings_tab_screen_test.dart | 8 +-- test/view/user/leaderboard_screen_test.dart | 4 +- test/view/user/leaderboard_widget_test.dart | 4 +- test/view/user/perf_stats_screen_test.dart | 6 +- test/view/user/search_screen_test.dart | 6 +- test/view/user/user_screen_test.dart | 4 +- 95 files changed, 303 insertions(+), 214 deletions(-) rename lib/src/{model/common => network}/http.dart (94%) rename lib/src/{model/common => network}/socket.dart (99%) create mode 100644 test/mock_server_responses.dart rename test/{model/common => network}/fake_websocket_channel.dart (98%) rename test/{model/common => network}/socket_test.dart (99%) diff --git a/lib/src/app.dart b/lib/src/app.dart index 11f86677b..48bbd7e3a 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -10,17 +10,20 @@ import 'package:lichess_mobile/src/constants.dart'; import 'package:lichess_mobile/src/model/account/account_repository.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/challenge/challenge_service.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/correspondence/correspondence_service.dart'; import 'package:lichess_mobile/src/model/notifications/notification_service.dart'; import 'package:lichess_mobile/src/model/settings/board_preferences.dart'; import 'package:lichess_mobile/src/model/settings/brightness.dart'; import 'package:lichess_mobile/src/model/settings/general_preferences.dart'; import 'package:lichess_mobile/src/navigation.dart'; +import 'package:lichess_mobile/src/network/http.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/connectivity.dart'; import 'package:lichess_mobile/src/utils/screen.dart'; +import 'package:logging/logging.dart'; + +final _logger = Logger('Application'); /// The main application widget. /// @@ -52,9 +55,6 @@ class _AppState extends ConsumerState { }, ); - // check if session is still active and delete it if it is not - checkSession(); - // Start services ref.read(notificationServiceProvider).start(); ref.read(challengeServiceProvider).start(); @@ -76,6 +76,9 @@ class _AppState extends ConsumerState { // Perform actions once when the app comes online. if (current.value?.isOnline == true && !_firstTimeOnlineCheck) { _firstTimeOnlineCheck = true; + // check if session is still active and delete it if it is not + checkSession(); + ref.read(correspondenceServiceProvider).syncGames(); } @@ -208,16 +211,24 @@ class _AppState extends ConsumerState { // check if session is still active final session = ref.read(authSessionProvider); if (session != null) { + _logger.fine( + 'Found a stored session: ${session.user.id}. Checking if it is still active.', + ); try { final client = ref.read(lichessClientProvider); - final response = await client - .get(Uri(path: '/api/account')) + final data = await client + .postReadJson( + Uri(path: '/api/token/test'), + body: session.token, + mapper: (json) => json, + ) .timeout(const Duration(seconds: 3)); - if (response.statusCode == 401) { + if (data[session.token] == null) { + _logger.fine('Session is not active. Deleting it.'); await ref.read(authSessionProvider.notifier).delete(); } } catch (e) { - debugPrint('Could not check session: $e'); + _logger.warning('Could not check session: $e'); } } } diff --git a/lib/src/binding.dart b/lib/src/binding.dart index 1ddfbf9eb..c001f7fa8 100644 --- a/lib/src/binding.dart +++ b/lib/src/binding.dart @@ -13,9 +13,9 @@ import 'package:lichess_mobile/src/db/secure_storage.dart'; import 'package:lichess_mobile/src/log.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/auth/session_storage.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/notifications/notification_service.dart'; import 'package:lichess_mobile/src/model/notifications/notifications.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:lichess_mobile/src/utils/string.dart'; import 'package:lichess_mobile/src/utils/system.dart'; import 'package:logging/logging.dart'; diff --git a/lib/src/init.dart b/lib/src/init.dart index 1965c7eed..837a5a0c6 100644 --- a/lib/src/init.dart +++ b/lib/src/init.dart @@ -6,9 +6,9 @@ import 'package:flutter/services.dart'; import 'package:flutter_displaymode/flutter_displaymode.dart'; import 'package:lichess_mobile/src/binding.dart'; import 'package:lichess_mobile/src/db/secure_storage.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/settings/board_preferences.dart'; import 'package:lichess_mobile/src/model/settings/preferences.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:lichess_mobile/src/utils/color_palette.dart'; import 'package:lichess_mobile/src/utils/screen.dart'; import 'package:lichess_mobile/src/utils/string.dart'; diff --git a/lib/src/model/account/account_preferences.dart b/lib/src/model/account/account_preferences.dart index 60d89224e..ee6950f08 100644 --- a/lib/src/model/account/account_preferences.dart +++ b/lib/src/model/account/account_preferences.dart @@ -1,7 +1,7 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:flutter/widgets.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; diff --git a/lib/src/model/account/account_repository.dart b/lib/src/model/account/account_repository.dart index b3e3a8420..be4f276dc 100644 --- a/lib/src/model/account/account_repository.dart +++ b/lib/src/model/account/account_repository.dart @@ -3,12 +3,12 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:http/http.dart' as http; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; import 'package:lichess_mobile/src/model/common/speed.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; import 'package:lichess_mobile/src/model/user/user_repository.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:logging/logging.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; diff --git a/lib/src/model/analysis/server_analysis_service.dart b/lib/src/model/analysis/server_analysis_service.dart index 6db960d91..a7e740a60 100644 --- a/lib/src/model/analysis/server_analysis_service.dart +++ b/lib/src/model/analysis/server_analysis_service.dart @@ -2,11 +2,11 @@ import 'dart:async'; import 'package:dartchess/dartchess.dart'; import 'package:flutter/foundation.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/game/game_repository.dart'; import 'package:lichess_mobile/src/model/game/game_socket_events.dart'; +import 'package:lichess_mobile/src/network/http.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'server_analysis_service.g.dart'; diff --git a/lib/src/model/auth/auth_controller.dart b/lib/src/model/auth/auth_controller.dart index afbdccf1b..00c319efe 100644 --- a/lib/src/model/auth/auth_controller.dart +++ b/lib/src/model/auth/auth_controller.dart @@ -1,7 +1,7 @@ import 'package:lichess_mobile/src/model/auth/auth_session.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/notifications/notification_service.dart'; +import 'package:lichess_mobile/src/network/http.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'auth_repository.dart'; diff --git a/lib/src/model/auth/auth_repository.dart b/lib/src/model/auth/auth_repository.dart index bc7a30284..57f2b4a79 100644 --- a/lib/src/model/auth/auth_repository.dart +++ b/lib/src/model/auth/auth_repository.dart @@ -4,8 +4,8 @@ import 'package:http/http.dart' as http; import 'package:lichess_mobile/src/constants.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/auth/bearer.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:logging/logging.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; diff --git a/lib/src/model/broadcast/broadcast_providers.dart b/lib/src/model/broadcast/broadcast_providers.dart index 0642c913e..2e46ce4f8 100644 --- a/lib/src/model/broadcast/broadcast_providers.dart +++ b/lib/src/model/broadcast/broadcast_providers.dart @@ -1,6 +1,6 @@ import 'package:lichess_mobile/src/model/broadcast/broadcast.dart'; import 'package:lichess_mobile/src/model/broadcast/broadcast_repository.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'broadcast_providers.g.dart'; diff --git a/lib/src/model/broadcast/broadcast_repository.dart b/lib/src/model/broadcast/broadcast_repository.dart index 05c6b6e7f..d461efe9c 100644 --- a/lib/src/model/broadcast/broadcast_repository.dart +++ b/lib/src/model/broadcast/broadcast_repository.dart @@ -3,8 +3,8 @@ import 'package:deep_pick/deep_pick.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:lichess_mobile/src/model/broadcast/broadcast.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/json.dart'; class BroadcastRepository { diff --git a/lib/src/model/broadcast/broadcast_round_controller.dart b/lib/src/model/broadcast/broadcast_round_controller.dart index d14118d8e..808f51726 100644 --- a/lib/src/model/broadcast/broadcast_round_controller.dart +++ b/lib/src/model/broadcast/broadcast_round_controller.dart @@ -6,9 +6,9 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:lichess_mobile/src/model/broadcast/broadcast.dart'; import 'package:lichess_mobile/src/model/broadcast/broadcast_repository.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; +import 'package:lichess_mobile/src/network/http.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:lichess_mobile/src/utils/json.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; diff --git a/lib/src/model/challenge/challenge_repository.dart b/lib/src/model/challenge/challenge_repository.dart index e44d5a707..67b091bc0 100644 --- a/lib/src/model/challenge/challenge_repository.dart +++ b/lib/src/model/challenge/challenge_repository.dart @@ -4,8 +4,8 @@ import 'package:deep_pick/deep_pick.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:http/http.dart' as http; import 'package:lichess_mobile/src/model/challenge/challenge.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'challenge_repository.g.dart'; diff --git a/lib/src/model/challenge/challenge_service.dart b/lib/src/model/challenge/challenge_service.dart index 37a076f04..294aefb15 100644 --- a/lib/src/model/challenge/challenge_service.dart +++ b/lib/src/model/challenge/challenge_service.dart @@ -7,10 +7,10 @@ import 'package:flutter/widgets.dart'; import 'package:lichess_mobile/src/model/challenge/challenge.dart'; import 'package:lichess_mobile/src/model/challenge/challenge_repository.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/notifications/notification_service.dart'; import 'package:lichess_mobile/src/model/notifications/notifications.dart'; import 'package:lichess_mobile/src/navigation.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; import 'package:lichess_mobile/src/utils/navigation.dart'; import 'package:lichess_mobile/src/view/game/game_screen.dart'; diff --git a/lib/src/model/correspondence/correspondence_service.dart b/lib/src/model/correspondence/correspondence_service.dart index f1e89d5f2..634221fcb 100644 --- a/lib/src/model/correspondence/correspondence_service.dart +++ b/lib/src/model/correspondence/correspondence_service.dart @@ -8,15 +8,15 @@ import 'package:flutter/widgets.dart'; import 'package:lichess_mobile/src/model/account/account_repository.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/auth/bearer.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/correspondence/correspondence_game_storage.dart'; import 'package:lichess_mobile/src/model/correspondence/offline_correspondence_game.dart'; import 'package:lichess_mobile/src/model/game/game_repository.dart'; import 'package:lichess_mobile/src/model/game/game_socket_events.dart'; import 'package:lichess_mobile/src/model/game/playable_game.dart'; import 'package:lichess_mobile/src/navigation.dart'; +import 'package:lichess_mobile/src/network/http.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:lichess_mobile/src/utils/navigation.dart'; import 'package:lichess_mobile/src/view/game/game_screen.dart'; import 'package:logging/logging.dart'; diff --git a/lib/src/model/game/chat_controller.dart b/lib/src/model/game/chat_controller.dart index 1d4f8c9cc..ddddc8f93 100644 --- a/lib/src/model/game/chat_controller.dart +++ b/lib/src/model/game/chat_controller.dart @@ -5,8 +5,8 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:lichess_mobile/src/db/database.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/game/game_controller.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:sqflite/sqflite.dart'; diff --git a/lib/src/model/game/game.dart b/lib/src/model/game/game.dart index a3408e080..13d11db99 100644 --- a/lib/src/model/game/game.dart +++ b/lib/src/model/game/game.dart @@ -8,11 +8,11 @@ import 'package:intl/intl.dart'; import 'package:lichess_mobile/src/model/account/account_preferences.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; import 'package:lichess_mobile/src/model/common/eval.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/node.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; import 'package:lichess_mobile/src/model/common/speed.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'game_status.dart'; import 'material_diff.dart'; diff --git a/lib/src/model/game/game_controller.dart b/lib/src/model/game/game_controller.dart index 89b866cdc..a75e1b8f3 100644 --- a/lib/src/model/game/game_controller.dart +++ b/lib/src/model/game/game_controller.dart @@ -13,11 +13,9 @@ import 'package:lichess_mobile/src/model/account/account_repository.dart'; import 'package:lichess_mobile/src/model/analysis/analysis_controller.dart'; import 'package:lichess_mobile/src/model/analysis/server_analysis_service.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/service/move_feedback.dart'; import 'package:lichess_mobile/src/model/common/service/sound_service.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/common/speed.dart'; import 'package:lichess_mobile/src/model/correspondence/correspondence_service.dart'; import 'package:lichess_mobile/src/model/game/archived_game.dart'; @@ -29,6 +27,8 @@ import 'package:lichess_mobile/src/model/game/game_storage.dart'; import 'package:lichess_mobile/src/model/game/material_diff.dart'; import 'package:lichess_mobile/src/model/game/playable_game.dart'; import 'package:lichess_mobile/src/model/settings/board_preferences.dart'; +import 'package:lichess_mobile/src/network/http.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:lichess_mobile/src/utils/rate_limit.dart'; import 'package:logging/logging.dart'; import 'package:result_extensions/result_extensions.dart'; diff --git a/lib/src/model/game/game_history.dart b/lib/src/model/game/game_history.dart index fa71d886b..dbea52b36 100644 --- a/lib/src/model/game/game_history.dart +++ b/lib/src/model/game/game_history.dart @@ -6,7 +6,6 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:lichess_mobile/src/model/account/account_repository.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/game/archived_game.dart'; import 'package:lichess_mobile/src/model/game/game_filter.dart'; @@ -14,6 +13,7 @@ import 'package:lichess_mobile/src/model/game/game_repository.dart'; import 'package:lichess_mobile/src/model/game/game_storage.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; import 'package:lichess_mobile/src/model/user/user_repository_providers.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/connectivity.dart'; import 'package:lichess_mobile/src/utils/riverpod.dart'; import 'package:result_extensions/result_extensions.dart'; diff --git a/lib/src/model/game/game_repository.dart b/lib/src/model/game/game_repository.dart index 7d342ef6c..84f56e4ad 100644 --- a/lib/src/model/game/game_repository.dart +++ b/lib/src/model/game/game_repository.dart @@ -1,12 +1,12 @@ import 'package:dartchess/dartchess.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:http/http.dart' as http; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; import 'package:lichess_mobile/src/model/game/archived_game.dart'; import 'package:lichess_mobile/src/model/game/game_filter.dart'; import 'package:lichess_mobile/src/model/game/playable_game.dart'; +import 'package:lichess_mobile/src/network/http.dart'; class GameRepository { const GameRepository(this.client); diff --git a/lib/src/model/game/game_repository_providers.dart b/lib/src/model/game/game_repository_providers.dart index 5006f2c6c..26fd2d839 100644 --- a/lib/src/model/game/game_repository_providers.dart +++ b/lib/src/model/game/game_repository_providers.dart @@ -1,8 +1,8 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/game/archived_game.dart'; import 'package:lichess_mobile/src/model/game/game_storage.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'game_repository.dart'; diff --git a/lib/src/model/game/game_share_service.dart b/lib/src/model/game/game_share_service.dart index 837fba675..8723a221a 100644 --- a/lib/src/model/game/game_share_service.dart +++ b/lib/src/model/game/game_share_service.dart @@ -2,9 +2,9 @@ import 'dart:convert'; import 'package:dartchess/dartchess.dart'; import 'package:lichess_mobile/src/constants.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/settings/board_preferences.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:share_plus/share_plus.dart'; diff --git a/lib/src/model/lobby/create_game_service.dart b/lib/src/model/lobby/create_game_service.dart index cb2fd64c7..30f1f9c45 100644 --- a/lib/src/model/lobby/create_game_service.dart +++ b/lib/src/model/lobby/create_game_service.dart @@ -5,11 +5,11 @@ import 'package:lichess_mobile/src/binding.dart'; import 'package:lichess_mobile/src/model/account/account_repository.dart'; import 'package:lichess_mobile/src/model/challenge/challenge.dart'; import 'package:lichess_mobile/src/model/challenge/challenge_repository.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/lobby/game_seek.dart'; import 'package:lichess_mobile/src/model/lobby/lobby_repository.dart'; +import 'package:lichess_mobile/src/network/http.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:logging/logging.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; diff --git a/lib/src/model/lobby/lobby_numbers.dart b/lib/src/model/lobby/lobby_numbers.dart index db7131ef9..adb4bf22e 100644 --- a/lib/src/model/lobby/lobby_numbers.dart +++ b/lib/src/model/lobby/lobby_numbers.dart @@ -1,6 +1,6 @@ import 'dart:async'; -import 'package:lichess_mobile/src/model/common/socket.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'lobby_numbers.g.dart'; diff --git a/lib/src/model/lobby/lobby_repository.dart b/lib/src/model/lobby/lobby_repository.dart index 38cad7d6e..a6a95f1df 100644 --- a/lib/src/model/lobby/lobby_repository.dart +++ b/lib/src/model/lobby/lobby_repository.dart @@ -2,9 +2,9 @@ import 'package:deep_pick/deep_pick.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:http/http.dart' as http; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'correspondence_challenge.dart'; diff --git a/lib/src/model/notifications/notification_service.dart b/lib/src/model/notifications/notification_service.dart index 41be595dd..c3c378750 100644 --- a/lib/src/model/notifications/notification_service.dart +++ b/lib/src/model/notifications/notification_service.dart @@ -8,9 +8,9 @@ import 'package:lichess_mobile/l10n/l10n.dart'; import 'package:lichess_mobile/src/binding.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/challenge/challenge_service.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/correspondence/correspondence_service.dart'; import 'package:lichess_mobile/src/model/notifications/notifications.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/badge_service.dart'; import 'package:lichess_mobile/src/utils/connectivity.dart'; import 'package:lichess_mobile/src/utils/l10n.dart'; diff --git a/lib/src/model/opening_explorer/opening_explorer_repository.dart b/lib/src/model/opening_explorer/opening_explorer_repository.dart index c4b7938c3..f8f6d5210 100644 --- a/lib/src/model/opening_explorer/opening_explorer_repository.dart +++ b/lib/src/model/opening_explorer/opening_explorer_repository.dart @@ -4,10 +4,10 @@ import 'package:dartchess/dartchess.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:http/http.dart'; import 'package:lichess_mobile/src/constants.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/speed.dart'; import 'package:lichess_mobile/src/model/opening_explorer/opening_explorer.dart'; import 'package:lichess_mobile/src/model/opening_explorer/opening_explorer_preferences.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'opening_explorer_repository.g.dart'; diff --git a/lib/src/model/puzzle/puzzle_activity.dart b/lib/src/model/puzzle/puzzle_activity.dart index 55a7a71cb..9addb76e8 100644 --- a/lib/src/model/puzzle/puzzle_activity.dart +++ b/lib/src/model/puzzle/puzzle_activity.dart @@ -3,10 +3,10 @@ import 'dart:async'; import 'package:async/async.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_providers.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_repository.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/riverpod.dart'; import 'package:result_extensions/result_extensions.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; diff --git a/lib/src/model/puzzle/puzzle_controller.dart b/lib/src/model/puzzle/puzzle_controller.dart index 425ebafcb..56a2a5e46 100644 --- a/lib/src/model/puzzle/puzzle_controller.dart +++ b/lib/src/model/puzzle/puzzle_controller.dart @@ -6,7 +6,6 @@ import 'package:dartchess/dartchess.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/node.dart'; import 'package:lichess_mobile/src/model/common/service/move_feedback.dart'; import 'package:lichess_mobile/src/model/common/service/sound_service.dart'; @@ -22,6 +21,7 @@ import 'package:lichess_mobile/src/model/puzzle/puzzle_service.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_session.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_streak.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_theme.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/rate_limit.dart'; import 'package:result_extensions/result_extensions.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; diff --git a/lib/src/model/puzzle/puzzle_providers.dart b/lib/src/model/puzzle/puzzle_providers.dart index de22f470f..8487c90ce 100644 --- a/lib/src/model/puzzle/puzzle_providers.dart +++ b/lib/src/model/puzzle/puzzle_providers.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_angle.dart'; @@ -13,6 +12,7 @@ import 'package:lichess_mobile/src/model/puzzle/puzzle_service.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_storage.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_theme.dart'; import 'package:lichess_mobile/src/model/puzzle/storm.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'puzzle_providers.g.dart'; diff --git a/lib/src/model/puzzle/puzzle_repository.dart b/lib/src/model/puzzle/puzzle_repository.dart index de6028f97..cd47368e8 100644 --- a/lib/src/model/puzzle/puzzle_repository.dart +++ b/lib/src/model/puzzle/puzzle_repository.dart @@ -8,9 +8,9 @@ import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:http/http.dart' as http; import 'package:intl/intl.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/json.dart'; import 'puzzle.dart'; diff --git a/lib/src/model/puzzle/puzzle_service.dart b/lib/src/model/puzzle/puzzle_service.dart index 0989724dc..f247d7c69 100644 --- a/lib/src/model/puzzle/puzzle_service.dart +++ b/lib/src/model/puzzle/puzzle_service.dart @@ -3,9 +3,9 @@ import 'dart:math' show max; import 'package:async/async.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_storage.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:logging/logging.dart'; import 'package:result_extensions/result_extensions.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; diff --git a/lib/src/model/puzzle/storm_controller.dart b/lib/src/model/puzzle/storm_controller.dart index 60300aaf4..544c890db 100644 --- a/lib/src/model/puzzle/storm_controller.dart +++ b/lib/src/model/puzzle/storm_controller.dart @@ -9,9 +9,9 @@ import 'package:flutter/services.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/service/move_feedback.dart'; import 'package:lichess_mobile/src/model/common/service/sound_service.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:result_extensions/result_extensions.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; diff --git a/lib/src/model/relation/online_friends.dart b/lib/src/model/relation/online_friends.dart index 7997c8b37..c18466d19 100644 --- a/lib/src/model/relation/online_friends.dart +++ b/lib/src/model/relation/online_friends.dart @@ -2,8 +2,8 @@ import 'dart:async'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'online_friends.g.dart'; diff --git a/lib/src/model/relation/relation_repository.dart b/lib/src/model/relation/relation_repository.dart index e2baf82e5..b82ee3332 100644 --- a/lib/src/model/relation/relation_repository.dart +++ b/lib/src/model/relation/relation_repository.dart @@ -1,8 +1,8 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:http/http.dart' as http; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/http.dart'; class RelationRepository { const RelationRepository(this.client); diff --git a/lib/src/model/relation/relation_repository_providers.dart b/lib/src/model/relation/relation_repository_providers.dart index 935721342..2c80f6144 100644 --- a/lib/src/model/relation/relation_repository_providers.dart +++ b/lib/src/model/relation/relation_repository_providers.dart @@ -1,6 +1,6 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'relation_repository.dart'; diff --git a/lib/src/model/study/study_repository.dart b/lib/src/model/study/study_repository.dart index bedc2ff78..b0e6b8446 100644 --- a/lib/src/model/study/study_repository.dart +++ b/lib/src/model/study/study_repository.dart @@ -1,9 +1,9 @@ import 'package:deep_pick/deep_pick.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:http/http.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/study/study.dart'; import 'package:lichess_mobile/src/model/study/study_filter.dart'; +import 'package:lichess_mobile/src/network/http.dart'; class StudyRepository { StudyRepository(this.client); diff --git a/lib/src/model/tv/live_tv_channels.dart b/lib/src/model/tv/live_tv_channels.dart index 0bd44d76f..cdc07605b 100644 --- a/lib/src/model/tv/live_tv_channels.dart +++ b/lib/src/model/tv/live_tv_channels.dart @@ -3,9 +3,9 @@ import 'dart:async'; import 'package:dartchess/dartchess.dart'; import 'package:deep_pick/deep_pick.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/tv/tv_socket_events.dart'; +import 'package:lichess_mobile/src/network/http.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'featured_player.dart'; diff --git a/lib/src/model/tv/tv_controller.dart b/lib/src/model/tv/tv_controller.dart index c6d97744c..68e0dd13b 100644 --- a/lib/src/model/tv/tv_controller.dart +++ b/lib/src/model/tv/tv_controller.dart @@ -4,10 +4,8 @@ import 'package:dartchess/dartchess.dart'; import 'package:deep_pick/deep_pick.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/service/sound_service.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/game/game.dart'; import 'package:lichess_mobile/src/model/game/game_socket_events.dart'; import 'package:lichess_mobile/src/model/game/game_status.dart'; @@ -16,6 +14,8 @@ import 'package:lichess_mobile/src/model/game/playable_game.dart'; import 'package:lichess_mobile/src/model/tv/tv_channel.dart'; import 'package:lichess_mobile/src/model/tv/tv_repository.dart'; import 'package:lichess_mobile/src/model/tv/tv_socket_events.dart'; +import 'package:lichess_mobile/src/network/http.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'tv_controller.freezed.dart'; diff --git a/lib/src/model/tv/tv_repository.dart b/lib/src/model/tv/tv_repository.dart index 804454ce2..aaff5f591 100644 --- a/lib/src/model/tv/tv_repository.dart +++ b/lib/src/model/tv/tv_repository.dart @@ -2,9 +2,9 @@ import 'package:deep_pick/deep_pick.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:http/http.dart' as http; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import './tv_channel.dart'; import './tv_game.dart'; diff --git a/lib/src/model/user/user_repository.dart b/lib/src/model/user/user_repository.dart index d77c4a741..858ff7669 100644 --- a/lib/src/model/user/user_repository.dart +++ b/lib/src/model/user/user_repository.dart @@ -1,10 +1,10 @@ import 'package:collection/collection.dart'; import 'package:deep_pick/deep_pick.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; import 'package:lichess_mobile/src/model/user/leaderboard.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/json.dart'; import 'streamer.dart'; diff --git a/lib/src/model/user/user_repository_providers.dart b/lib/src/model/user/user_repository_providers.dart index 9e45d0917..cdd6c8324 100644 --- a/lib/src/model/user/user_repository_providers.dart +++ b/lib/src/model/user/user_repository_providers.dart @@ -1,8 +1,8 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; import 'package:lichess_mobile/src/model/user/leaderboard.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'streamer.dart'; diff --git a/lib/src/model/common/http.dart b/lib/src/network/http.dart similarity index 94% rename from lib/src/model/common/http.dart rename to lib/src/network/http.dart index d3ad3f73a..94d9a3488 100644 --- a/lib/src/model/common/http.dart +++ b/lib/src/network/http.dart @@ -146,10 +146,14 @@ class LoggingClient extends BaseClient { /// Lichess HTTP client. /// -/// - All requests go to the lichess server, defined in [kLichessHost]. -/// - Sets the Authorization header when a token has been stored. -/// - Sets the user-agent header with the app version, build number, and device info. If the user is logged in, it also includes the user's id. -/// - Logs all requests and responses with status code >= 400. +/// * All requests made with [head], [get], [post], [put], [patch], [delete] target +/// the lichess server, defined in [kLichessHost]. It does not apply to the low-level +/// [send] method. +/// * Sets the Authorization header when a token has been stored. +/// * Sets the user-agent header with the app version, build number, and device info. If the user is logged in, it also includes the user's id. +/// * Logs all requests and responses with status code >= 400. +/// * When a response has the 401 status, checks if the session token is still valid, +/// and deletes the session if it's not. class LichessClient implements Client { LichessClient(this._inner, this._ref); @@ -180,6 +184,10 @@ class LichessClient implements Client { _logIfError(response); + if (response.statusCode == 401 && session != null) { + _checkSessionToken(session); + } + return response; } catch (e, st) { _logger.warning('Request to ${request.url} failed: $e', e, st); @@ -187,6 +195,18 @@ class LichessClient implements Client { } } + /// Checks if the session token is still valid, and delete session if it's not. + Future _checkSessionToken(AuthSessionState session) async { + final data = await postReadJson( + Uri(path: '/api/token/test'), + mapper: (json) => json, + ).timeout(const Duration(seconds: 5)); + if (data[session.token] == null) { + _logger.fine('Session is not active. Deleting it.'); + await _ref.read(authSessionProvider.notifier).delete(); + } + } + void _logIfError(BaseResponse response) { if (response.request != null && response.statusCode >= 400) { final request = response.request!; diff --git a/lib/src/model/common/socket.dart b/lib/src/network/socket.dart similarity index 99% rename from lib/src/model/common/socket.dart rename to lib/src/network/socket.dart index 34c28f223..197c1a58e 100644 --- a/lib/src/model/common/socket.dart +++ b/lib/src/network/socket.dart @@ -11,7 +11,7 @@ import 'package:lichess_mobile/src/binding.dart'; import 'package:lichess_mobile/src/constants.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/auth/bearer.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:logging/logging.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; diff --git a/lib/src/utils/connectivity.dart b/lib/src/utils/connectivity.dart index df9309a6d..6d80a51ce 100644 --- a/lib/src/utils/connectivity.dart +++ b/lib/src/utils/connectivity.dart @@ -5,7 +5,7 @@ import 'package:flutter/widgets.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:http/http.dart'; import 'package:lichess_mobile/src/constants.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/rate_limit.dart'; import 'package:logging/logging.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; diff --git a/lib/src/view/account/edit_profile_screen.dart b/lib/src/view/account/edit_profile_screen.dart index 2a6529aba..c567d5e36 100644 --- a/lib/src/view/account/edit_profile_screen.dart +++ b/lib/src/view/account/edit_profile_screen.dart @@ -3,8 +3,8 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:lichess_mobile/src/model/account/account_repository.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; import 'package:lichess_mobile/src/view/user/countries.dart'; diff --git a/lib/src/view/analysis/analysis_screen.dart b/lib/src/view/analysis/analysis_screen.dart index d49ba403b..19a103a2c 100644 --- a/lib/src/view/analysis/analysis_screen.dart +++ b/lib/src/view/analysis/analysis_screen.dart @@ -15,13 +15,13 @@ import 'package:lichess_mobile/src/model/analysis/server_analysis_service.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; import 'package:lichess_mobile/src/model/common/eval.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/engine/engine.dart'; import 'package:lichess_mobile/src/model/engine/evaluation_service.dart'; import 'package:lichess_mobile/src/model/game/game_repository_providers.dart'; import 'package:lichess_mobile/src/model/game/game_share_service.dart'; import 'package:lichess_mobile/src/model/settings/brightness.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/styles/lichess_icons.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/connectivity.dart'; diff --git a/lib/src/view/broadcast/broadcast_round_screen.dart b/lib/src/view/broadcast/broadcast_round_screen.dart index f3a2a7b4e..4a4d82879 100644 --- a/lib/src/view/broadcast/broadcast_round_screen.dart +++ b/lib/src/view/broadcast/broadcast_round_screen.dart @@ -7,8 +7,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:lichess_mobile/src/model/broadcast/broadcast.dart'; import 'package:lichess_mobile/src/model/broadcast/broadcast_round_controller.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/duration.dart'; import 'package:lichess_mobile/src/utils/lichess_assets.dart'; diff --git a/lib/src/view/game/archived_game_screen.dart b/lib/src/view/game/archived_game_screen.dart index d9418fec6..a4666b286 100644 --- a/lib/src/view/game/archived_game_screen.dart +++ b/lib/src/view/game/archived_game_screen.dart @@ -4,11 +4,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:intl/intl.dart'; import 'package:lichess_mobile/src/model/analysis/analysis_controller.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/game/archived_game.dart'; import 'package:lichess_mobile/src/model/game/game.dart'; import 'package:lichess_mobile/src/model/game/game_repository_providers.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; import 'package:lichess_mobile/src/utils/navigation.dart'; import 'package:lichess_mobile/src/view/analysis/analysis_screen.dart'; diff --git a/lib/src/view/game/game_common_widgets.dart b/lib/src/view/game/game_common_widgets.dart index a17350963..8d3718cf5 100644 --- a/lib/src/view/game/game_common_widgets.dart +++ b/lib/src/view/game/game_common_widgets.dart @@ -4,12 +4,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:intl/intl.dart'; import 'package:lichess_mobile/src/model/challenge/challenge.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/time_increment.dart'; import 'package:lichess_mobile/src/model/game/game.dart'; import 'package:lichess_mobile/src/model/game/game_share_service.dart'; import 'package:lichess_mobile/src/model/lobby/game_seek.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; import 'package:lichess_mobile/src/utils/share.dart'; import 'package:lichess_mobile/src/widgets/adaptive_action_sheet.dart'; diff --git a/lib/src/view/game/game_list_tile.dart b/lib/src/view/game/game_list_tile.dart index 1c1213c1b..5009b8494 100644 --- a/lib/src/view/game/game_list_tile.dart +++ b/lib/src/view/game/game_list_tile.dart @@ -4,11 +4,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:intl/intl.dart'; import 'package:lichess_mobile/src/model/analysis/analysis_controller.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/game/archived_game.dart'; import 'package:lichess_mobile/src/model/game/game_share_service.dart'; import 'package:lichess_mobile/src/model/game/game_status.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/styles/lichess_colors.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; diff --git a/lib/src/view/game/game_screen.dart b/lib/src/view/game/game_screen.dart index 00e3c9c23..9dda6892f 100644 --- a/lib/src/view/game/game_screen.dart +++ b/lib/src/view/game/game_screen.dart @@ -4,13 +4,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:lichess_mobile/src/model/account/account_repository.dart'; import 'package:lichess_mobile/src/model/challenge/challenge.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/game/game_history.dart'; import 'package:lichess_mobile/src/model/lobby/create_game_service.dart'; import 'package:lichess_mobile/src/model/lobby/game_seek.dart'; import 'package:lichess_mobile/src/model/lobby/game_setup_preferences.dart'; import 'package:lichess_mobile/src/navigation.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; import 'package:lichess_mobile/src/utils/navigation.dart'; import 'package:lichess_mobile/src/view/game/game_loading_board.dart'; diff --git a/lib/src/view/game/ping_rating.dart b/lib/src/view/game/ping_rating.dart index 6248f3e43..4b1f41684 100644 --- a/lib/src/view/game/ping_rating.dart +++ b/lib/src/view/game/ping_rating.dart @@ -1,7 +1,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:lichess_mobile/src/widgets/feedback.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; diff --git a/lib/src/view/play/create_custom_game_screen.dart b/lib/src/view/play/create_custom_game_screen.dart index 23348be80..a6ff680df 100644 --- a/lib/src/view/play/create_custom_game_screen.dart +++ b/lib/src/view/play/create_custom_game_screen.dart @@ -10,13 +10,13 @@ import 'package:lichess_mobile/src/model/common/chess.dart'; import 'package:lichess_mobile/src/model/common/game.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/common/time_increment.dart'; import 'package:lichess_mobile/src/model/lobby/create_game_service.dart'; import 'package:lichess_mobile/src/model/lobby/game_seek.dart'; import 'package:lichess_mobile/src/model/lobby/game_setup_preferences.dart'; import 'package:lichess_mobile/src/model/lobby/lobby_repository.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; import 'package:lichess_mobile/src/utils/navigation.dart'; diff --git a/lib/src/view/play/online_bots_screen.dart b/lib/src/view/play/online_bots_screen.dart index 91139e47a..74355f23d 100644 --- a/lib/src/view/play/online_bots_screen.dart +++ b/lib/src/view/play/online_bots_screen.dart @@ -4,11 +4,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_linkify/flutter_linkify.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; import 'package:lichess_mobile/src/model/user/user_repository.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; import 'package:lichess_mobile/src/utils/navigation.dart'; diff --git a/lib/src/view/puzzle/puzzle_screen.dart b/lib/src/view/puzzle/puzzle_screen.dart index 04e28521f..fa701f8ed 100644 --- a/lib/src/view/puzzle/puzzle_screen.dart +++ b/lib/src/view/puzzle/puzzle_screen.dart @@ -8,7 +8,6 @@ import 'package:lichess_mobile/src/constants.dart'; import 'package:lichess_mobile/src/model/analysis/analysis_controller.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/engine/evaluation_service.dart'; import 'package:lichess_mobile/src/model/game/game_repository_providers.dart'; @@ -22,6 +21,7 @@ import 'package:lichess_mobile/src/model/puzzle/puzzle_service.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_theme.dart'; import 'package:lichess_mobile/src/model/settings/board_preferences.dart'; import 'package:lichess_mobile/src/navigation.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/connectivity.dart'; import 'package:lichess_mobile/src/utils/immersive_mode.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; diff --git a/lib/src/view/puzzle/streak_screen.dart b/lib/src/view/puzzle/streak_screen.dart index 1507428ed..b682b49eb 100644 --- a/lib/src/view/puzzle/streak_screen.dart +++ b/lib/src/view/puzzle/streak_screen.dart @@ -7,13 +7,13 @@ import 'package:lichess_mobile/src/constants.dart'; import 'package:lichess_mobile/src/model/analysis/analysis_controller.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_angle.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_controller.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_providers.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_service.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_streak.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_theme.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/styles/lichess_icons.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/immersive_mode.dart'; diff --git a/lib/src/view/relation/following_screen.dart b/lib/src/view/relation/following_screen.dart index b3ce4c3c0..18a72bbb7 100644 --- a/lib/src/view/relation/following_screen.dart +++ b/lib/src/view/relation/following_screen.dart @@ -3,11 +3,11 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/relation/online_friends.dart'; import 'package:lichess_mobile/src/model/relation/relation_repository.dart'; import 'package:lichess_mobile/src/model/relation/relation_repository_providers.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; import 'package:lichess_mobile/src/utils/navigation.dart'; diff --git a/lib/src/view/user/perf_stats_screen.dart b/lib/src/view/user/perf_stats_screen.dart index 2ecda93d4..bbb6a612d 100644 --- a/lib/src/view/user/perf_stats_screen.dart +++ b/lib/src/view/user/perf_stats_screen.dart @@ -11,12 +11,12 @@ import 'package:intl/intl.dart'; import 'package:lichess_mobile/l10n/l10n.dart'; import 'package:lichess_mobile/src/constants.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; import 'package:lichess_mobile/src/model/game/game_filter.dart'; import 'package:lichess_mobile/src/model/game/game_repository.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; import 'package:lichess_mobile/src/model/user/user_repository_providers.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/styles/lichess_icons.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/duration.dart'; diff --git a/lib/src/view/user/user_activity.dart b/lib/src/view/user/user_activity.dart index faf915755..d5cd53199 100644 --- a/lib/src/view/user/user_activity.dart +++ b/lib/src/view/user/user_activity.dart @@ -3,10 +3,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:intl/intl.dart'; import 'package:lichess_mobile/src/model/account/account_repository.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; import 'package:lichess_mobile/src/model/user/user_repository.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/styles/lichess_colors.dart'; import 'package:lichess_mobile/src/styles/lichess_icons.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; diff --git a/lib/src/view/user/user_screen.dart b/lib/src/view/user/user_screen.dart index 747e2210a..7ae829104 100644 --- a/lib/src/view/user/user_screen.dart +++ b/lib/src/view/user/user_screen.dart @@ -2,10 +2,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:http/http.dart' show ClientException; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/relation/relation_repository.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; import 'package:lichess_mobile/src/model/user/user_repository_providers.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/styles/lichess_icons.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; diff --git a/lib/src/view/watch/watch_tab_screen.dart b/lib/src/view/watch/watch_tab_screen.dart index 68c49af20..fd44e08d1 100644 --- a/lib/src/view/watch/watch_tab_screen.dart +++ b/lib/src/view/watch/watch_tab_screen.dart @@ -5,13 +5,13 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:lichess_mobile/src/model/broadcast/broadcast_providers.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/tv/featured_player.dart'; import 'package:lichess_mobile/src/model/tv/tv_channel.dart'; import 'package:lichess_mobile/src/model/tv/tv_game.dart'; import 'package:lichess_mobile/src/model/tv/tv_repository.dart'; import 'package:lichess_mobile/src/model/user/user_repository_providers.dart'; import 'package:lichess_mobile/src/navigation.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; import 'package:lichess_mobile/src/utils/navigation.dart'; diff --git a/test/app_test.dart b/test/app_test.dart index 0017db01c..86f6e0d47 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -1,14 +1,19 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:http/testing.dart'; import 'package:lichess_mobile/src/app.dart'; import 'package:lichess_mobile/src/navigation.dart'; +import 'package:lichess_mobile/src/network/http.dart'; +import 'mock_server_responses.dart'; +import 'model/auth/fake_session_storage.dart'; +import 'test_helpers.dart'; import 'test_provider_scope.dart'; void main() { testWidgets('App loads', (tester) async { - final app = await makeProviderScope( + final app = await makeTestProviderScope( tester, child: const Application(), ); @@ -20,7 +25,7 @@ void main() { testWidgets('App loads with system theme, which defaults to light', (tester) async { - final app = await makeProviderScope( + final app = await makeTestProviderScope( tester, child: const Application(), ); @@ -33,8 +38,56 @@ void main() { ); }); + // testWidgets('App checks a stored session', (tester) async { + // int tokenTestRequests = 0; + // final mockClient = MockClient((request) { + // if (request.url.path == '/api/token/test') { + // tokenTestRequests++; + // return mockResponse( + // ''' +// { + // "${fakeSession.token}": { + // "scopes": "web:mobile", + // "userId": "${fakeSession.user.id}" + // } +// } + // ''', + // 200, + // ); + // } else if (request.url.path == '/api/account') { + // return mockResponse( + // mockApiAccountResponse(fakeSession.user.name), + // 200, + // ); + // } + // return mockResponse('', 404); + // }); + + // final app = await makeTestProviderScope( + // tester, + // child: const Application(), + // userSession: fakeSession, + // overrides: [ + // lichessClientProvider + // .overrideWith((ref) => LichessClient(mockClient, ref)), + // ], + // ); + + // await tester.pumpWidget(app); + + // expect(find.byType(MaterialApp), findsOneWidget); + + // // wait for the session check request to complete + // await tester.pump(const Duration(milliseconds: 100)); + + // expect(tokenTestRequests, 1); + + // // session is still active + // expect(find.text('Hello testUser'), findsOneWidget); + // }); + testWidgets('Bottom navigation', (tester) async { - final app = await makeProviderScope( + final app = await makeTestProviderScope( tester, child: const Application(), ); diff --git a/test/mock_server_responses.dart b/test/mock_server_responses.dart new file mode 100644 index 000000000..5145f36d5 --- /dev/null +++ b/test/mock_server_responses.dart @@ -0,0 +1,40 @@ +/// Mock server response for /api/account endpoint. +String mockApiAccountResponse(String username) => ''' +{ + "id": "${username.toLowerCase()}", + "username": "$username", + "createdAt": 1290415680000, + "seenAt": 1290415680000, + "title": "GM", + "patron": true, + "perfs": { + "blitz": { + "games": 2340, + "rating": 1681, + "rd": 30, + "prog": 10 + }, + "rapid": { + "games": 2340, + "rating": 1677, + "rd": 30, + "prog": 10 + }, + "classical": { + "games": 2340, + "rating": 1618, + "rd": 30, + "prog": 10 + } + }, + "profile": { + "country": "France", + "location": "Lille", + "bio": "test bio", + "firstName": "John", + "lastName": "Doe", + "fideRating": 1800, + "links": "http://test.com" + } +} +'''; diff --git a/test/model/account/account_repository_test.dart b/test/model/account/account_repository_test.dart index 27aeb64c1..efb69915a 100644 --- a/test/model/account/account_repository_test.dart +++ b/test/model/account/account_repository_test.dart @@ -2,7 +2,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; import 'package:lichess_mobile/src/model/account/account_preferences.dart'; import 'package:lichess_mobile/src/model/account/account_repository.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import '../../test_container.dart'; import '../../test_helpers.dart'; diff --git a/test/model/auth/auth_controller_test.dart b/test/model/auth/auth_controller_test.dart index cbeeeff79..e0df8d189 100644 --- a/test/model/auth/auth_controller_test.dart +++ b/test/model/auth/auth_controller_test.dart @@ -6,11 +6,12 @@ import 'package:lichess_mobile/src/model/auth/auth_controller.dart'; import 'package:lichess_mobile/src/model/auth/auth_repository.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/auth/session_storage.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:mocktail/mocktail.dart'; +import '../../mock_server_responses.dart'; import '../../test_container.dart'; import '../../test_helpers.dart'; @@ -22,15 +23,6 @@ class Listener extends Mock { void call(T? previous, T value); } -final client = MockClient((request) { - if (request.url.path == '/api/account') { - return mockResponse(testAccountResponse, 200); - } else if (request.method == 'DELETE' && request.url.path == '/api/token') { - return mockResponse('ok', 200); - } - return mockResponse('', 404); -}); - void main() { final mockSessionStorage = MockSessionStorage(); final mockFlutterAppAuth = MockFlutterAppAuth(); @@ -47,6 +39,18 @@ void main() { const loading = AsyncLoading(); const nullData = AsyncData(null); + final client = MockClient((request) { + if (request.url.path == '/api/account') { + return mockResponse( + mockApiAccountResponse(testUserSession.user.name), + 200, + ); + } else if (request.method == 'DELETE' && request.url.path == '/api/token') { + return mockResponse('ok', 200); + } + return mockResponse('', 404); + }); + setUpAll(() { registerFallbackValue( AuthorizationTokenRequest( @@ -156,46 +160,6 @@ void main() { }); } -const testAccountResponse = ''' -{ - "id": "test", - "username": "test", - "createdAt": 1290415680000, - "seenAt": 1290415680000, - "title": "GM", - "patron": true, - "perfs": { - "blitz": { - "games": 2340, - "rating": 1681, - "rd": 30, - "prog": 10 - }, - "rapid": { - "games": 2340, - "rating": 1677, - "rd": 30, - "prog": 10 - }, - "classical": { - "games": 2340, - "rating": 1618, - "rd": 30, - "prog": 10 - } - }, - "profile": { - "country": "France", - "location": "Lille", - "bio": "test bio", - "firstName": "John", - "lastName": "Doe", - "fideRating": 1800, - "links": "http://test.com" - } -} -'''; - final signInResponse = AuthorizationTokenResponse( 'testToken', null, diff --git a/test/model/broadcast/broadcast_repository_test.dart b/test/model/broadcast/broadcast_repository_test.dart index fb3f95f26..7d7b78f0f 100644 --- a/test/model/broadcast/broadcast_repository_test.dart +++ b/test/model/broadcast/broadcast_repository_test.dart @@ -2,8 +2,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; import 'package:lichess_mobile/src/model/broadcast/broadcast.dart'; import 'package:lichess_mobile/src/model/broadcast/broadcast_repository.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import '../../test_container.dart'; import '../../test_helpers.dart'; diff --git a/test/model/challenge/challenge_repository_test.dart b/test/model/challenge/challenge_repository_test.dart index 412d9c2bb..b40f62c9a 100644 --- a/test/model/challenge/challenge_repository_test.dart +++ b/test/model/challenge/challenge_repository_test.dart @@ -3,8 +3,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; import 'package:lichess_mobile/src/model/challenge/challenge.dart'; import 'package:lichess_mobile/src/model/challenge/challenge_repository.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import '../../test_container.dart'; import '../../test_helpers.dart'; diff --git a/test/model/challenge/challenge_service_test.dart b/test/model/challenge/challenge_service_test.dart index 80e6e5768..10872457a 100644 --- a/test/model/challenge/challenge_service_test.dart +++ b/test/model/challenge/challenge_service_test.dart @@ -12,10 +12,10 @@ import 'package:lichess_mobile/src/model/notifications/notification_service.dart import 'package:lichess_mobile/src/model/user/user.dart'; import 'package:mocktail/mocktail.dart'; +import '../../network/fake_websocket_channel.dart'; +import '../../network/socket_test.dart'; import '../../test_container.dart'; import '../auth/fake_session_storage.dart'; -import '../common/fake_websocket_channel.dart'; -import '../common/socket_test.dart'; class NotificationDisplayMock extends Mock implements FlutterLocalNotificationsPlugin {} diff --git a/test/model/game/game_repository_test.dart b/test/model/game/game_repository_test.dart index 658eb532f..176bdb07d 100644 --- a/test/model/game/game_repository_test.dart +++ b/test/model/game/game_repository_test.dart @@ -2,10 +2,10 @@ import 'package:dartchess/dartchess.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/game/archived_game.dart'; import 'package:lichess_mobile/src/model/game/game_repository.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import '../../test_container.dart'; import '../../test_helpers.dart'; diff --git a/test/model/lobby/lobby_repository_test.dart b/test/model/lobby/lobby_repository_test.dart index 6c92f42ef..e18f00f7c 100644 --- a/test/model/lobby/lobby_repository_test.dart +++ b/test/model/lobby/lobby_repository_test.dart @@ -1,10 +1,10 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/lobby/correspondence_challenge.dart'; import 'package:lichess_mobile/src/model/lobby/lobby_repository.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import '../../test_container.dart'; import '../../test_helpers.dart'; diff --git a/test/model/notifications/notification_service_test.dart b/test/model/notifications/notification_service_test.dart index 5b6b8bee9..472455172 100644 --- a/test/model/notifications/notification_service_test.dart +++ b/test/model/notifications/notification_service_test.dart @@ -5,13 +5,14 @@ import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/correspondence/correspondence_service.dart'; import 'package:lichess_mobile/src/model/game/playable_game.dart'; import 'package:lichess_mobile/src/model/notifications/notification_service.dart'; import 'package:lichess_mobile/src/model/notifications/notifications.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:mocktail/mocktail.dart'; + import '../../binding.dart'; import '../../test_container.dart'; import '../../test_helpers.dart'; diff --git a/test/model/opening_explorer/opening_explorer_repository_test.dart b/test/model/opening_explorer/opening_explorer_repository_test.dart index 013fd5516..ffdaa4b93 100644 --- a/test/model/opening_explorer/opening_explorer_repository_test.dart +++ b/test/model/opening_explorer/opening_explorer_repository_test.dart @@ -2,10 +2,10 @@ import 'package:dartchess/dartchess.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/speed.dart'; import 'package:lichess_mobile/src/model/opening_explorer/opening_explorer.dart'; import 'package:lichess_mobile/src/model/opening_explorer/opening_explorer_repository.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import '../../test_container.dart'; import '../../test_helpers.dart'; diff --git a/test/model/puzzle/puzzle_repository_test.dart b/test/model/puzzle/puzzle_repository_test.dart index 5647f327a..6098c0aa5 100644 --- a/test/model/puzzle/puzzle_repository_test.dart +++ b/test/model/puzzle/puzzle_repository_test.dart @@ -1,8 +1,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_repository.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import '../../test_container.dart'; import '../../test_helpers.dart'; diff --git a/test/model/puzzle/puzzle_service_test.dart b/test/model/puzzle/puzzle_service_test.dart index 34aa9a8ad..df896a6ed 100644 --- a/test/model/puzzle/puzzle_service_test.dart +++ b/test/model/puzzle/puzzle_service_test.dart @@ -5,7 +5,6 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle.dart'; @@ -13,6 +12,7 @@ import 'package:lichess_mobile/src/model/puzzle/puzzle_angle.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_batch_storage.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_service.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_theme.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import '../../test_container.dart'; import '../../test_helpers.dart'; @@ -318,7 +318,7 @@ void main() { expect(nbReq, equals(1)); final data = await storage.fetch(userId: const UserId('testUserId')); - expect(data?.solved, equals(IList(const []))); + expect(data?.solved, equals(IList(const []))); expect(data?.unsolved[0].puzzle.id, equals(const PuzzleId('20yWT'))); expect(next?.puzzle.puzzle.id, equals(const PuzzleId('20yWT'))); expect(next?.glicko?.rating, equals(1834.54)); diff --git a/test/model/relation/relation_repository_test.dart b/test/model/relation/relation_repository_test.dart index d190c9ff5..afe1fb958 100644 --- a/test/model/relation/relation_repository_test.dart +++ b/test/model/relation/relation_repository_test.dart @@ -1,9 +1,9 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/relation/relation_repository.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import '../../test_container.dart'; import '../../test_helpers.dart'; diff --git a/test/model/user/user_repository_test.dart b/test/model/user/user_repository_test.dart index 68bec60d9..87c1a6cf6 100644 --- a/test/model/user/user_repository_test.dart +++ b/test/model/user/user_repository_test.dart @@ -1,12 +1,12 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; import 'package:lichess_mobile/src/model/user/leaderboard.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; import 'package:lichess_mobile/src/model/user/user_repository.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import '../../test_container.dart'; import '../../test_helpers.dart'; diff --git a/test/model/common/fake_websocket_channel.dart b/test/network/fake_websocket_channel.dart similarity index 98% rename from test/model/common/fake_websocket_channel.dart rename to test/network/fake_websocket_channel.dart index fce314cdc..659b0cdd7 100644 --- a/test/model/common/fake_websocket_channel.dart +++ b/test/network/fake_websocket_channel.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:async/src/stream_sink_transformer.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:stream_channel/stream_channel.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; diff --git a/test/model/common/socket_test.dart b/test/network/socket_test.dart similarity index 99% rename from test/model/common/socket_test.dart rename to test/network/socket_test.dart index 3a5eb66e0..86e5d34d8 100644 --- a/test/model/common/socket_test.dart +++ b/test/network/socket_test.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'fake_websocket_channel.dart'; diff --git a/test/test_container.dart b/test/test_container.dart index 9e21f5ff1..daad1f169 100644 --- a/test/test_container.dart +++ b/test/test_container.dart @@ -8,10 +8,10 @@ import 'package:intl/intl.dart'; import 'package:lichess_mobile/src/crashlytics.dart'; import 'package:lichess_mobile/src/db/database.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/service/sound_service.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/notifications/notification_service.dart'; +import 'package:lichess_mobile/src/network/http.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:lichess_mobile/src/utils/connectivity.dart'; import 'package:logging/logging.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart'; @@ -19,8 +19,8 @@ import 'package:sqflite_common_ffi/sqflite_ffi.dart'; import './fake_crashlytics.dart'; import './model/common/service/fake_sound_service.dart'; import 'binding.dart'; -import 'model/common/fake_websocket_channel.dart'; import 'model/notifications/fake_notification_display.dart'; +import 'network/fake_websocket_channel.dart'; import 'utils/fake_connectivity.dart'; /// A mock client that always returns a 200 empty response. diff --git a/test/test_provider_scope.dart b/test/test_provider_scope.dart index 4f2077558..18064f509 100644 --- a/test/test_provider_scope.dart +++ b/test/test_provider_scope.dart @@ -14,11 +14,11 @@ import 'package:lichess_mobile/src/db/database.dart'; import 'package:lichess_mobile/src/model/account/account_preferences.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/auth/session_storage.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/service/sound_service.dart'; -import 'package:lichess_mobile/src/model/common/socket.dart'; import 'package:lichess_mobile/src/model/notifications/notification_service.dart'; import 'package:lichess_mobile/src/model/settings/board_preferences.dart'; +import 'package:lichess_mobile/src/network/http.dart'; +import 'package:lichess_mobile/src/network/socket.dart'; import 'package:lichess_mobile/src/utils/connectivity.dart'; import 'package:logging/logging.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart'; @@ -27,8 +27,8 @@ import 'package:visibility_detector/visibility_detector.dart'; import './fake_crashlytics.dart'; import './model/common/service/fake_sound_service.dart'; import 'binding.dart'; -import 'model/common/fake_websocket_channel.dart'; import 'model/notifications/fake_notification_display.dart'; +import 'network/fake_websocket_channel.dart'; import 'test_helpers.dart'; import 'utils/fake_connectivity.dart'; @@ -45,14 +45,14 @@ final mockClient = MockClient((request) async { /// The [overrides] parameter can be used to override any provider in the app. /// The [userSession] parameter can be used to set the initial user session state. /// The [defaultPreferences] parameter can be used to set the initial shared preferences. -Future makeProviderScopeApp( +Future makeTestProviderScopeApp( WidgetTester tester, { required Widget home, List? overrides, AuthSessionState? userSession, Map? defaultPreferences, }) async { - return makeProviderScope( + return makeTestProviderScope( tester, child: MaterialApp( localizationsDelegates: AppLocalizations.localizationsDelegates, @@ -79,7 +79,7 @@ Future makeProviderScopeApp( /// The [overrides] parameter can be used to override any provider in the app. /// The [userSession] parameter can be used to set the initial user session state. /// The [defaultPreferences] parameter can be used to set the initial shared preferences. -Future makeProviderScope( +Future makeTestProviderScope( WidgetTester tester, { required Widget child, List? overrides, diff --git a/test/view/analysis/analysis_screen_test.dart b/test/view/analysis/analysis_screen_test.dart index 0c74d1246..4c68c8476 100644 --- a/test/view/analysis/analysis_screen_test.dart +++ b/test/view/analysis/analysis_screen_test.dart @@ -29,7 +29,7 @@ void main() { group('Analysis Screen', () { testWidgets('displays correct move and position', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: AnalysisScreen( pgnOrId: sanMoves, @@ -56,7 +56,7 @@ void main() { }); testWidgets('move backwards and forward', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: AnalysisScreen( pgnOrId: sanMoves, diff --git a/test/view/board_editor/board_editor_screen_test.dart b/test/view/board_editor/board_editor_screen_test.dart index 37b702185..1511d59c2 100644 --- a/test/view/board_editor/board_editor_screen_test.dart +++ b/test/view/board_editor/board_editor_screen_test.dart @@ -12,7 +12,7 @@ import '../../test_provider_scope.dart'; void main() { group('Board Editor', () { testWidgets('Displays initial FEN on start', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const BoardEditorScreen(), ); @@ -37,7 +37,7 @@ void main() { }); testWidgets('Flip board', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const BoardEditorScreen(), ); @@ -57,7 +57,7 @@ void main() { }); testWidgets('Side to play and castling rights', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const BoardEditorScreen(), ); @@ -120,7 +120,7 @@ void main() { }); testWidgets('Castling rights ignored when rook is missing', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const BoardEditorScreen(), ); @@ -145,7 +145,7 @@ void main() { testWidgets('Possible en passant squares are calculated correctly', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const BoardEditorScreen(), ); @@ -182,7 +182,7 @@ void main() { }); testWidgets('Can drag pieces to new squares', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const BoardEditorScreen(), ); @@ -211,7 +211,7 @@ void main() { }); testWidgets('illegal position cannot be analyzed', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const BoardEditorScreen(), ); @@ -231,7 +231,7 @@ void main() { }); testWidgets('Delete pieces via bin button', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const BoardEditorScreen(), ); @@ -273,7 +273,7 @@ void main() { }); testWidgets('Add pieces via tap and pan', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const BoardEditorScreen(), ); @@ -297,7 +297,7 @@ void main() { }); testWidgets('Drag pieces onto the board', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const BoardEditorScreen(), ); diff --git a/test/view/broadcast/broadcasts_list_screen_test.dart b/test/view/broadcast/broadcasts_list_screen_test.dart index e5907ee7e..f5da2b584 100644 --- a/test/view/broadcast/broadcasts_list_screen_test.dart +++ b/test/view/broadcast/broadcasts_list_screen_test.dart @@ -1,6 +1,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/view/broadcast/broadcasts_list_screen.dart'; import 'package:network_image_mock/network_image_mock.dart'; @@ -24,7 +24,7 @@ void main() { 'Displays broadcast tournament screen', variant: kPlatformVariant, (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const BroadcastsListScreen(), overrides: [ @@ -48,7 +48,7 @@ void main() { 'Scroll broadcast tournament screen', variant: kPlatformVariant, (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const BroadcastsListScreen(), overrides: [ diff --git a/test/view/coordinate_training/coordinate_training_screen_test.dart b/test/view/coordinate_training/coordinate_training_screen_test.dart index 87e4f1cc9..ab5f65e5b 100644 --- a/test/view/coordinate_training/coordinate_training_screen_test.dart +++ b/test/view/coordinate_training/coordinate_training_screen_test.dart @@ -13,7 +13,7 @@ void main() { group('Coordinate Training', () { testWidgets('Initial state when started in FindSquare mode', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const CoordinateTrainingScreen(), ); @@ -52,7 +52,7 @@ void main() { }); testWidgets('Tap wrong square', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const CoordinateTrainingScreen(), ); @@ -101,7 +101,7 @@ void main() { }); testWidgets('Tap correct square', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const CoordinateTrainingScreen(), ); diff --git a/test/view/game/archived_game_screen_test.dart b/test/view/game/archived_game_screen_test.dart index 7ade011d1..cc09d0f7e 100644 --- a/test/view/game/archived_game_screen_test.dart +++ b/test/view/game/archived_game_screen_test.dart @@ -4,7 +4,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; import 'package:lichess_mobile/src/model/common/speed.dart'; @@ -12,6 +11,7 @@ import 'package:lichess_mobile/src/model/game/archived_game.dart'; import 'package:lichess_mobile/src/model/game/game_status.dart'; import 'package:lichess_mobile/src/model/game/player.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/view/game/archived_game_screen.dart'; import 'package:lichess_mobile/src/view/game/game_player.dart'; import 'package:lichess_mobile/src/widgets/bottom_bar_button.dart'; @@ -32,7 +32,7 @@ void main() { testWidgets( 'loads game data if only game id is provided', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const ArchivedGameScreen( gameId: GameId('qVChCOTc'), @@ -65,7 +65,7 @@ void main() { testWidgets( 'displays game data and last fen immediately, then moves', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: ArchivedGameScreen( gameData: gameData, @@ -138,7 +138,7 @@ void main() { ); testWidgets('navigate game positions', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: ArchivedGameScreen( gameData: gameData, diff --git a/test/view/opening_explorer/opening_explorer_screen_test.dart b/test/view/opening_explorer/opening_explorer_screen_test.dart index 3e4eea871..6d0a16971 100644 --- a/test/view/opening_explorer/opening_explorer_screen_test.dart +++ b/test/view/opening_explorer/opening_explorer_screen_test.dart @@ -7,13 +7,13 @@ import 'package:http/testing.dart'; import 'package:lichess_mobile/src/model/analysis/analysis_controller.dart'; import 'package:lichess_mobile/src/model/auth/auth_session.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/opening_explorer/opening_explorer.dart'; import 'package:lichess_mobile/src/model/opening_explorer/opening_explorer_preferences.dart'; import 'package:lichess_mobile/src/model/settings/preferences.dart'; import 'package:lichess_mobile/src/model/settings/preferences_storage.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/view/opening_explorer/opening_explorer_screen.dart'; import '../../test_helpers.dart'; @@ -63,7 +63,7 @@ void main() { testWidgets( 'master opening explorer loads', (WidgetTester tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const OpeningExplorerScreen( pgn: '', @@ -112,7 +112,7 @@ void main() { testWidgets( 'lichess opening explorer loads', (WidgetTester tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const OpeningExplorerScreen( pgn: '', @@ -167,7 +167,7 @@ void main() { testWidgets( 'player opening explorer loads', (WidgetTester tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const OpeningExplorerScreen( pgn: '', diff --git a/test/view/over_the_board/over_the_board_screen_test.dart b/test/view/over_the_board/over_the_board_screen_test.dart index defb4f45b..febe1c161 100644 --- a/test/view/over_the_board/over_the_board_screen_test.dart +++ b/test/view/over_the_board/over_the_board_screen_test.dart @@ -203,7 +203,7 @@ Future initOverTheBoardGame( WidgetTester tester, TimeIncrement timeIncrement, ) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const OverTheBoardScreen(), ); diff --git a/test/view/puzzle/puzzle_screen_test.dart b/test/view/puzzle/puzzle_screen_test.dart index f0e169af9..7cc0dca6a 100644 --- a/test/view/puzzle/puzzle_screen_test.dart +++ b/test/view/puzzle/puzzle_screen_test.dart @@ -6,7 +6,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; import 'package:lichess_mobile/src/model/account/account_preferences.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle.dart'; @@ -14,6 +13,7 @@ import 'package:lichess_mobile/src/model/puzzle/puzzle_angle.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_batch_storage.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_storage.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_theme.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/utils/string.dart'; import 'package:lichess_mobile/src/view/puzzle/puzzle_screen.dart'; import 'package:lichess_mobile/src/widgets/bottom_bar_button.dart'; @@ -47,7 +47,7 @@ void main() { (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: PuzzleScreen( angle: const PuzzleTheme(PuzzleThemeKey.mix), @@ -78,7 +78,7 @@ void main() { 'Loads puzzle directly by passing a puzzleId', variant: kPlatformVariant, (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: PuzzleScreen( angle: const PuzzleTheme(PuzzleThemeKey.mix), @@ -104,7 +104,7 @@ void main() { ); testWidgets('Loads next puzzle when no puzzleId is passed', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const PuzzleScreen( angle: PuzzleTheme(PuzzleThemeKey.mix), @@ -151,7 +151,7 @@ void main() { when(() => mockHistoryStorage.fetch(puzzleId: puzzle2.puzzle.id)) .thenAnswer((_) async => puzzle2); - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: PuzzleScreen( angle: const PuzzleTheme(PuzzleThemeKey.mix), @@ -264,7 +264,7 @@ void main() { when(() => mockHistoryStorage.fetch(puzzleId: puzzle2.puzzle.id)) .thenAnswer((_) async => puzzle2); - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: PuzzleScreen( angle: const PuzzleTheme(PuzzleThemeKey.mix), @@ -377,7 +377,7 @@ void main() { return mockResponse('', 404); }); - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: PuzzleScreen( angle: const PuzzleTheme(PuzzleThemeKey.mix), diff --git a/test/view/puzzle/storm_screen_test.dart b/test/view/puzzle/storm_screen_test.dart index e7e10ba21..ac581af0d 100644 --- a/test/view/puzzle/storm_screen_test.dart +++ b/test/view/puzzle/storm_screen_test.dart @@ -4,11 +4,11 @@ import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_providers.dart'; import 'package:lichess_mobile/src/model/puzzle/puzzle_repository.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/view/puzzle/storm_screen.dart'; import '../../test_helpers.dart'; @@ -28,7 +28,7 @@ void main() { (tester) async { final SemanticsHandle handle = tester.ensureSemantics(); - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const StormScreen(), overrides: [ @@ -49,7 +49,7 @@ void main() { testWidgets( 'Load puzzle and play white pieces', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const StormScreen(), overrides: [ @@ -73,7 +73,7 @@ void main() { testWidgets( 'Play one puzzle', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const StormScreen(), overrides: [ @@ -128,7 +128,7 @@ void main() { ); testWidgets('shows end run result', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const StormScreen(), overrides: [ @@ -173,7 +173,7 @@ void main() { }); testWidgets('play wrong move', (tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const StormScreen(), overrides: [ diff --git a/test/view/settings/settings_tab_screen_test.dart b/test/view/settings/settings_tab_screen_test.dart index e83b855a6..b907dc94a 100644 --- a/test/view/settings/settings_tab_screen_test.dart +++ b/test/view/settings/settings_tab_screen_test.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; import 'package:lichess_mobile/src/db/database.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/view/settings/settings_tab_screen.dart'; import 'package:lichess_mobile/src/widgets/list.dart'; @@ -26,7 +26,7 @@ void main() { (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const SettingsTabScreen(), ); @@ -46,7 +46,7 @@ void main() { testWidgets( "don't show signOut if no session", (WidgetTester tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const SettingsTabScreen(), ); @@ -61,7 +61,7 @@ void main() { testWidgets( 'signout', (WidgetTester tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const SettingsTabScreen(), userSession: fakeSession, diff --git a/test/view/user/leaderboard_screen_test.dart b/test/view/user/leaderboard_screen_test.dart index 1950ae020..40575d6b6 100644 --- a/test/view/user/leaderboard_screen_test.dart +++ b/test/view/user/leaderboard_screen_test.dart @@ -1,7 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/view/user/leaderboard_screen.dart'; import '../../test_helpers.dart'; @@ -21,7 +21,7 @@ void main() { (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, overrides: [ lichessClientProvider diff --git a/test/view/user/leaderboard_widget_test.dart b/test/view/user/leaderboard_widget_test.dart index fe63f0a9c..a34e0ebd5 100644 --- a/test/view/user/leaderboard_widget_test.dart +++ b/test/view/user/leaderboard_widget_test.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/view/user/leaderboard_screen.dart'; import 'package:lichess_mobile/src/view/user/leaderboard_widget.dart'; @@ -21,7 +21,7 @@ void main() { 'accessibility and basic info showing test', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: Column(children: [LeaderboardWidget()]), overrides: [ diff --git a/test/view/user/perf_stats_screen_test.dart b/test/view/user/perf_stats_screen_test.dart index 82144e818..a2a208f8e 100644 --- a/test/view/user/perf_stats_screen_test.dart +++ b/test/view/user/perf_stats_screen_test.dart @@ -1,8 +1,8 @@ import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/perf.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/view/user/perf_stats_screen.dart'; import 'package:lichess_mobile/src/widgets/platform.dart'; @@ -27,7 +27,7 @@ void main() { (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: PerfStatsScreen( user: fakeUser, @@ -59,7 +59,7 @@ void main() { testWidgets( 'screen loads, required stats are shown', (WidgetTester tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: PerfStatsScreen( user: fakeUser, diff --git a/test/view/user/search_screen_test.dart b/test/view/user/search_screen_test.dart index d1129c9c9..93579a2ef 100644 --- a/test/view/user/search_screen_test.dart +++ b/test/view/user/search_screen_test.dart @@ -3,7 +3,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/view/user/search_screen.dart'; import 'package:lichess_mobile/src/widgets/user_list_tile.dart'; @@ -25,7 +25,7 @@ void main() { testWidgets( 'should see search results', (WidgetTester tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const SearchScreen(), overrides: [ @@ -66,7 +66,7 @@ void main() { testWidgets( 'should see "no result" when search finds nothing', (WidgetTester tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const SearchScreen(), overrides: [ diff --git a/test/view/user/user_screen_test.dart b/test/view/user/user_screen_test.dart index be6e66435..91648e6db 100644 --- a/test/view/user/user_screen_test.dart +++ b/test/view/user/user_screen_test.dart @@ -1,8 +1,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:http/testing.dart'; -import 'package:lichess_mobile/src/model/common/http.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/user/user.dart'; +import 'package:lichess_mobile/src/network/http.dart'; import 'package:lichess_mobile/src/view/user/user_screen.dart'; import '../../model/user/user_repository_test.dart'; @@ -38,7 +38,7 @@ void main() { testWidgets( 'should see activity and recent games', (WidgetTester tester) async { - final app = await makeProviderScopeApp( + final app = await makeTestProviderScopeApp( tester, home: const UserScreen(user: testUser), overrides: [