From 70caeaccc39d6ee4f9b5e3e721671ec28d27bc82 Mon Sep 17 00:00:00 2001 From: Aayushmaan Date: Mon, 11 Mar 2024 19:55:51 +0530 Subject: [PATCH 1/4] bfix: handles error incase of unsuccessful logout --- lib/services/user_config.dart | 7 ++++--- .../settings_view_models/app_setting_view_model.dart | 7 ++++--- lib/view_model/lang_view_model.dart | 2 +- .../after_auth_screens/app_settings/app_settings_page.dart | 6 +++++- test/service_tests/user_config_test.dart | 1 - test/view_model_tests/lang_view_model_test.dart | 5 +++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/services/user_config.dart b/lib/services/user_config.dart index e7543c6b2..359aa3637 100644 --- a/lib/services/user_config.dart +++ b/lib/services/user_config.dart @@ -132,11 +132,11 @@ class UserConfig { /// **returns**: /// * `Future`: returns future of bool type. Future userLogOut() async { + bool isLogOutSuccessful = false; try { final result = await databaseFunctions.gqlAuthMutation(queries.logout()) as QueryResult?; if (result != null && result.data!['logout'] == true) { - navigationService.pop(); navigationService.pushDialog( const CustomProgressDialog( key: Key('LogoutProgress'), @@ -161,11 +161,12 @@ class UserConfig { // } await organisation.clear(); _currentUser = User(id: 'null', authToken: 'null'); + isLogOutSuccessful = true; } } catch (e) { - return false; + isLogOutSuccessful = false; } - return true; + return isLogOutSuccessful; } /// Updates the user joined organization. diff --git a/lib/view_model/after_auth_view_models/settings_view_models/app_setting_view_model.dart b/lib/view_model/after_auth_view_models/settings_view_models/app_setting_view_model.dart index 5e9024ff0..b7bfe8005 100644 --- a/lib/view_model/after_auth_view_models/settings_view_models/app_setting_view_model.dart +++ b/lib/view_model/after_auth_view_models/settings_view_models/app_setting_view_model.dart @@ -14,10 +14,11 @@ class AppSettingViewModel extends BaseModel { /// None /// /// **returns**: - /// None - Future logout() async { + /// * `Future`: A [Future] that resolves to a [bool] value indicating whether the user has been logged out. + Future logout() async { // push custom alert dialog with the confirmation message. - await userConfig.userLogOut(); + final bool isloggedOut = await userConfig.userLogOut(); + return isloggedOut; } /// Launches a website using the provided URL. diff --git a/lib/view_model/lang_view_model.dart b/lib/view_model/lang_view_model.dart index 2308b9601..061cf63e6 100644 --- a/lib/view_model/lang_view_model.dart +++ b/lib/view_model/lang_view_model.dart @@ -137,7 +137,7 @@ class AppLanguage extends BaseModel { /// **returns**: /// None Future selectLanguagePress() async { - if (userConfig.loggedIn) { + if (userConfig.currentUser.id != 'null') { dbLanguageUpdate(); navigationService.popAndPushScreen('/appSettingsPage', arguments: ''); } else { diff --git a/lib/views/after_auth_screens/app_settings/app_settings_page.dart b/lib/views/after_auth_screens/app_settings/app_settings_page.dart index 4fb2d3029..15808550a 100644 --- a/lib/views/after_auth_screens/app_settings/app_settings_page.dart +++ b/lib/views/after_auth_screens/app_settings/app_settings_page.dart @@ -302,7 +302,11 @@ class AppSettingsPage extends StatelessWidget { successText: 'LogOut', success: () async { try { - await model.logout(); + final bool isLogoutSuccessful = + await model.logout(); + if (!isLogoutSuccessful) { + throw Error(); //checks whether the logout was successful or not. + } navigationService.pop(); navigationService.removeAllAndPush( '/selectLang', diff --git a/test/service_tests/user_config_test.dart b/test/service_tests/user_config_test.dart index 4d0e6154f..3b281e335 100644 --- a/test/service_tests/user_config_test.dart +++ b/test/service_tests/user_config_test.dart @@ -197,7 +197,6 @@ void main() async { expect(loggedOut, true); - verify(navigationService.pop()); expect(userBox.isEmpty, true); expect(urlBox.isEmpty, true); expect(orgBox.isEmpty, true); diff --git a/test/view_model_tests/lang_view_model_test.dart b/test/view_model_tests/lang_view_model_test.dart index 0924fdc31..d1a9491ab 100644 --- a/test/view_model_tests/lang_view_model_test.dart +++ b/test/view_model_tests/lang_view_model_test.dart @@ -7,6 +7,7 @@ import 'package:mockito/mockito.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:talawa/constants/routing_constants.dart'; import 'package:talawa/models/mainscreen_navigation_args.dart'; +import 'package:talawa/models/user/user_info.dart'; import 'package:talawa/services/graphql_config.dart'; import 'package:talawa/view_model/lang_view_model.dart'; @@ -100,7 +101,7 @@ void main() { await model.initialize(); // consider if user is not logged in. - when(userConfig.loggedIn).thenReturn(false); + when(userConfig.currentUser).thenReturn(User(id: 'null')); when( navigationService.pushScreen( @@ -126,7 +127,7 @@ void main() { ); // consider if user is logged in. - when(userConfig.loggedIn).thenReturn(true); + when(userConfig.currentUser).thenReturn(User(id: 'xyz1')); when( navigationService.popAndPushScreen( From 610f6f6018f4213c138ccb760e171741fae33d00 Mon Sep 17 00:00:00 2001 From: Aayushmaan Date: Tue, 12 Mar 2024 13:22:23 +0530 Subject: [PATCH 2/4] test: adds Test if Logout is successful test --- .../app_settings/app_setting_page_test.dart | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/widget_tests/after_auth_screens/app_settings/app_setting_page_test.dart b/test/widget_tests/after_auth_screens/app_settings/app_setting_page_test.dart index 2705a2181..5ab7fbf34 100644 --- a/test/widget_tests/after_auth_screens/app_settings/app_setting_page_test.dart +++ b/test/widget_tests/after_auth_screens/app_settings/app_setting_page_test.dart @@ -308,5 +308,27 @@ Future main() async { final logoutButton = find.textContaining('LogOut'); await tester.tap(logoutButton); }); + + testWidgets('Test if Logout is successful', (tester) async { + final model = AppSettingViewModel(); + when(model.logout()).thenAnswer((_) async => true); + + await tester.pumpWidget(createChangePassScreenDark()); + await tester.pumpAndSettle(); + + await tester.tap(find.byKey(const Key('Logout'))); + await tester.pumpAndSettle(); + + final logoutButton = find.textContaining('LogOut'); + await tester.tap(logoutButton); + + verify(navigationService.pop()); + verify( + navigationService.removeAllAndPush( + '/selectLang', + '/', + ), + ); + }); }); } From bfa7ba6660b0a961d964d5286eabd1c985d77a28 Mon Sep 17 00:00:00 2001 From: Aayushmaan Date: Mon, 18 Mar 2024 18:58:03 +0530 Subject: [PATCH 3/4] ptch: routes to login page after logout --- .../after_auth_screens/app_settings/app_settings_page.dart | 5 +++-- .../app_settings/app_setting_page_test.dart | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/views/after_auth_screens/app_settings/app_settings_page.dart b/lib/views/after_auth_screens/app_settings/app_settings_page.dart index 15808550a..523cfe9e0 100644 --- a/lib/views/after_auth_screens/app_settings/app_settings_page.dart +++ b/lib/views/after_auth_screens/app_settings/app_settings_page.dart @@ -309,8 +309,9 @@ class AppSettingsPage extends StatelessWidget { } navigationService.pop(); navigationService.removeAllAndPush( - '/selectLang', - '/', + Routes.setUrlScreen, + Routes.splashScreen, + arguments: '', ); } catch (e) { navigationService.pushDialog( diff --git a/test/widget_tests/after_auth_screens/app_settings/app_setting_page_test.dart b/test/widget_tests/after_auth_screens/app_settings/app_setting_page_test.dart index 5ab7fbf34..04d89e1de 100644 --- a/test/widget_tests/after_auth_screens/app_settings/app_setting_page_test.dart +++ b/test/widget_tests/after_auth_screens/app_settings/app_setting_page_test.dart @@ -8,6 +8,7 @@ import 'package:mockito/mockito.dart'; import 'package:provider/provider.dart'; import 'package:talawa/constants/constants.dart'; import 'package:talawa/constants/custom_theme.dart'; +import 'package:talawa/constants/routing_constants.dart'; import 'package:talawa/models/language/language_model.dart'; import 'package:talawa/router.dart' as router; import 'package:talawa/services/graphql_config.dart'; @@ -325,8 +326,9 @@ Future main() async { verify(navigationService.pop()); verify( navigationService.removeAllAndPush( - '/selectLang', - '/', + Routes.setUrlScreen, + Routes.splashScreen, + arguments: '', ), ); }); From 26aba3c1ccb153d43a956000a4d0f0f8061fd1a9 Mon Sep 17 00:00:00 2001 From: Aayushmaan Date: Wed, 20 Mar 2024 14:38:47 +0530 Subject: [PATCH 4/4] docs: changed a sentence to a better non reductant one --- .../settings_view_models/app_setting_view_model.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/view_model/after_auth_view_models/settings_view_models/app_setting_view_model.dart b/lib/view_model/after_auth_view_models/settings_view_models/app_setting_view_model.dart index b7bfe8005..49da3a680 100644 --- a/lib/view_model/after_auth_view_models/settings_view_models/app_setting_view_model.dart +++ b/lib/view_model/after_auth_view_models/settings_view_models/app_setting_view_model.dart @@ -14,7 +14,7 @@ class AppSettingViewModel extends BaseModel { /// None /// /// **returns**: - /// * `Future`: A [Future] that resolves to a [bool] value indicating whether the user has been logged out. + /// * `Future`: Logs the user out and returns the logout status as a [bool]. Future logout() async { // push custom alert dialog with the confirmation message. final bool isloggedOut = await userConfig.userLogOut();