-
-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe03e05
commit 4d54905
Showing
8 changed files
with
331 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,42 @@ import '../../helpers/test_locator.dart'; | |
|
||
// import '../../helpers/test_helpers.dart'; | ||
|
||
/// Mock Class for Flutter Secure Storage for error detection. | ||
class MockFlutterSecureStorage extends Mock implements FlutterSecureStorage { | ||
@override | ||
Future<void> write({ | ||
required String key, | ||
required String? value, | ||
IOSOptions? iOptions, | ||
AndroidOptions? aOptions, | ||
LinuxOptions? lOptions, | ||
WebOptions? webOptions, | ||
MacOsOptions? mOptions, | ||
WindowsOptions? wOptions, | ||
}) async { | ||
if (key == "userEmail" || key == "userPassword") { | ||
throw Exception("Storing error"); | ||
} | ||
return Future.value(null); | ||
} | ||
|
||
@override | ||
Future<String?> read({ | ||
required String key, | ||
IOSOptions? iOptions, | ||
AndroidOptions? aOptions, | ||
LinuxOptions? lOptions, | ||
WebOptions? webOptions, | ||
MacOsOptions? mOptions, | ||
WindowsOptions? wOptions, | ||
}) async { | ||
if (key == "userEmail" || key == "userPassword") { | ||
throw Exception("Unable to read"); | ||
} | ||
return Future.value(null); | ||
} | ||
} | ||
|
||
final data = { | ||
'login': { | ||
'user': { | ||
|
@@ -214,6 +250,36 @@ Future<void> main() async { | |
contains("Unable to read"), | ||
); | ||
}); | ||
test('Should handle exception while storing data', () async { | ||
final model = LoginViewModel(); | ||
FlutterSecureStorage.setMockInitialValues( | ||
{"userEmail": "[email protected]", "userPassword": "password123"}, | ||
); | ||
final mockSecureStorage = MockFlutterSecureStorage(); | ||
model.secureStorage = mockSecureStorage; | ||
|
||
String log = ""; | ||
|
||
await runZonedGuarded( | ||
() async { | ||
await model.storingCredentialsInSecureStorage(); | ||
}, | ||
(error, stack) { | ||
expect(error, isA<Exception>()); | ||
expect(error.toString(), contains("Storing error")); | ||
expect(stack, isNotNull); | ||
}, | ||
zoneSpecification: ZoneSpecification( | ||
print: (self, parent, zone, line) { | ||
log = line; | ||
}, | ||
), | ||
); | ||
expect( | ||
log, | ||
contains("Storing error"), | ||
); | ||
}); | ||
}); | ||
} | ||
|
||
|
@@ -235,22 +301,3 @@ class MockUserConfig extends Mock implements UserConfig { | |
@override | ||
Future<bool> updateUser(User user) async => true; | ||
} | ||
|
||
/// Mock Class for Flutter Secure Storage. | ||
class MockFlutterSecureStorage extends Mock implements FlutterSecureStorage { | ||
@override | ||
Future<String?> read({ | ||
required String key, | ||
IOSOptions? iOptions, | ||
AndroidOptions? aOptions, | ||
LinuxOptions? lOptions, | ||
WebOptions? webOptions, | ||
MacOsOptions? mOptions, | ||
WindowsOptions? wOptions, | ||
}) async { | ||
if (key == "userEmail" || key == "userPassword") { | ||
throw Exception("Unable to read"); | ||
} | ||
return Future.value(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// ignore_for_file: talawa_api_doc | ||
// ignore_for_file: talawa_good_doc_comments | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
@@ -554,6 +556,36 @@ void main() { | |
), | ||
); | ||
}); | ||
test('Should handle exception while storing data', () async { | ||
final model = SignupDetailsViewModel(); | ||
FlutterSecureStorage.setMockInitialValues( | ||
{"userEmail": "[email protected]", "userPassword": "password123"}, | ||
); | ||
final mockSecureStorage = MockFlutterSecureStorage(); | ||
model.secureStorage = mockSecureStorage; | ||
|
||
String log = ""; | ||
|
||
await runZonedGuarded( | ||
() async { | ||
await model.storingCredentialsInSecureStorage(); | ||
}, | ||
(error, stack) { | ||
expect(error, isA<Exception>()); | ||
expect(error.toString(), contains("Storing error")); | ||
expect(stack, isNotNull); | ||
}, | ||
zoneSpecification: ZoneSpecification( | ||
print: (self, parent, zone, line) { | ||
log = line; | ||
}, | ||
), | ||
); | ||
expect( | ||
log, | ||
contains("Storing error"), | ||
); | ||
}); | ||
}); | ||
} | ||
|
||
|
@@ -579,3 +611,39 @@ class MockUserConfig extends Mock implements UserConfig { | |
@override | ||
Future<dynamic> updateUserMemberRequestOrg(List<OrgInfo> orgs) async => null; | ||
} | ||
|
||
/// Mock Class for Flutter Secure Storage for error detection. | ||
class MockFlutterSecureStorage extends Mock implements FlutterSecureStorage { | ||
@override | ||
Future<void> write({ | ||
required String key, | ||
required String? value, | ||
IOSOptions? iOptions, | ||
AndroidOptions? aOptions, | ||
LinuxOptions? lOptions, | ||
WebOptions? webOptions, | ||
MacOsOptions? mOptions, | ||
WindowsOptions? wOptions, | ||
}) async { | ||
if (key == "userEmail" || key == "userPassword") { | ||
throw Exception("Storing error"); | ||
} | ||
return Future.value(null); | ||
} | ||
|
||
@override | ||
Future<String?> read({ | ||
required String key, | ||
IOSOptions? iOptions, | ||
AndroidOptions? aOptions, | ||
LinuxOptions? lOptions, | ||
WebOptions? webOptions, | ||
MacOsOptions? mOptions, | ||
WindowsOptions? wOptions, | ||
}) async { | ||
if (key == "userEmail" || key == "userPassword") { | ||
throw Exception("Unable to read"); | ||
} | ||
return Future.value(null); | ||
} | ||
} |
Oops, something went wrong.