Skip to content

Commit

Permalink
bfix: handles error incase of unsuccessful logout
Browse files Browse the repository at this point in the history
  • Loading branch information
am-casper committed Mar 11, 2024
1 parent 5861b65 commit 60fee87
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
7 changes: 4 additions & 3 deletions lib/services/user_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ class UserConfig {
/// **returns**:
/// * `Future<bool>`: returns future of bool type.
Future<bool> 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'),
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ class AppSettingViewModel extends BaseModel {
/// None
///
/// **returns**:
/// None
Future<void> logout() async {
/// * `Future<bool>`: A [Future] that resolves to a [bool] value indicating whether the user has been logged out.
Future<bool> 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.
Expand Down
2 changes: 1 addition & 1 deletion lib/view_model/lang_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class AppLanguage extends BaseModel {
/// **returns**:
/// None
Future<void> selectLanguagePress() async {
if (userConfig.loggedIn) {
if (userConfig.currentUser.id != 'null') {
dbLanguageUpdate();
navigationService.popAndPushScreen('/appSettingsPage', arguments: '');
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion test/service_tests/user_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions test/view_model_tests/lang_view_model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 60fee87

Please sign in to comment.