Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logout issue #4

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>`: Logs the user out and returns the logout status as a [bool].
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
11 changes: 8 additions & 3 deletions lib/views/after_auth_screens/app_settings/app_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,16 @@ 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',
'/',
Routes.setUrlScreen,
Routes.splashScreen,
arguments: '',
);
} catch (e) {
navigationService.pushDialog(
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
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -308,5 +309,28 @@ Future<void> 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(
Routes.setUrlScreen,
Routes.splashScreen,
arguments: '',
),
);
});
});
}
Loading