stack_wallet/test/flutter_secure_storage_interface_test.dart

52 lines
1.8 KiB
Dart
Raw Normal View History

2022-08-26 08:11:35 +00:00
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'flutter_secure_storage_interface_test.mocks.dart';
@GenerateMocks([FlutterSecureStorage])
void main() {
test("SecureStorageWrapper write", () async {
final secureStore = MockFlutterSecureStorage();
when(secureStore.write(key: "testKey", value: "some value"))
.thenAnswer((_) async => null);
2022-11-09 22:43:26 +00:00
final wrapper = SecureStorageWrapper(store: secureStore, isDesktop: false);
2022-08-26 08:11:35 +00:00
await expectLater(
() async => await wrapper.write(key: "testKey", value: "some value"),
returnsNormally);
verify(secureStore.write(key: "testKey", value: "some value")).called(1);
verifyNoMoreInteractions(secureStore);
});
test("SecureStorageWrapper read", () async {
final secureStore = MockFlutterSecureStorage();
when(secureStore.read(key: "testKey"))
.thenAnswer((_) async => "some value");
2022-11-09 22:43:26 +00:00
final wrapper = SecureStorageWrapper(store: secureStore, isDesktop: false);
2022-08-26 08:11:35 +00:00
final result = await wrapper.read(key: "testKey");
expect(result, "some value");
verify(secureStore.read(key: "testKey")).called(1);
verifyNoMoreInteractions(secureStore);
});
test("SecureStorageWrapper delete", () async {
final secureStore = MockFlutterSecureStorage();
when(secureStore.delete(key: "testKey")).thenAnswer((_) async {});
2022-11-09 22:43:26 +00:00
final wrapper = SecureStorageWrapper(store: secureStore, isDesktop: false);
2022-08-26 08:11:35 +00:00
await expectLater(
() async => await wrapper.delete(key: "testKey"), returnsNormally);
verify(secureStore.delete(key: "testKey")).called(1);
verifyNoMoreInteractions(secureStore);
});
}