@@ -5,7 +5,6 @@ import 'package:amplify_auth_cognito_dart/amplify_auth_cognito_dart.dart';
5
5
import 'package:amplify_auth_cognito_dart/src/credentials/cognito_keys.dart' ;
6
6
import 'package:amplify_auth_cognito_dart/src/credentials/device_metadata_repository.dart' ;
7
7
import 'package:amplify_auth_cognito_dart/src/sdk/cognito_identity_provider.dart' ;
8
- import 'package:amplify_auth_cognito_dart/src/state/cognito_state_machine.dart' ;
9
8
import 'package:amplify_auth_cognito_test/common/mock_clients.dart' ;
10
9
import 'package:amplify_auth_cognito_test/common/mock_config.dart' ;
11
10
import 'package:amplify_auth_cognito_test/common/mock_secure_storage.dart' ;
@@ -23,19 +22,15 @@ void main() {
23
22
24
23
late DeviceMetadataRepository repo;
25
24
late AmplifyAuthCognitoDart plugin;
26
- late CognitoAuthStateMachine stateMachine;
27
- late MockSecureStorage secureStorage;
28
25
29
26
Future <String ?> getDeviceKey () async {
30
27
final secrets = await repo.get (username);
31
28
return secrets? .deviceKey;
32
29
}
33
30
34
- group (
35
- 'fetchCurrentDevice expected return value and DeviceNotTrackedException' ,
36
- () {
31
+ group ('fetchCurrentDevice' , () {
37
32
setUp (() async {
38
- secureStorage = MockSecureStorage ();
33
+ final secureStorage = MockSecureStorage ();
39
34
seedStorage (
40
35
secureStorage,
41
36
userPoolKeys: userPoolKeys,
@@ -45,74 +40,58 @@ void main() {
45
40
plugin = AmplifyAuthCognitoDart (
46
41
secureStorageFactory: (_) => secureStorage,
47
42
);
48
- stateMachine = plugin.stateMachine;
49
43
await plugin.configure (
50
44
config: mockConfig,
51
45
authProviderRepo: testAuthRepo,
52
46
);
53
- final mockIdp = MockCognitoIdentityProviderClient (
54
- getDevice: () async => mockDeviceResponse,
55
- forgetDevice: () async {},
56
- );
57
- stateMachine.addInstance <CognitoIdentityProviderClient >(mockIdp);
58
- repo = stateMachine.getOrCreate <DeviceMetadataRepository >();
47
+ repo = plugin.stateMachine.getOrCreate <DeviceMetadataRepository >();
59
48
});
60
49
61
- test (
62
- 'should get the current device. current device id should be equal to the local device id' ,
63
- () async {
64
- final currentDeviceKey = await getDeviceKey ();
65
- expect (currentDeviceKey, isNotNull);
66
- final currentDevice = await plugin. fetchCurrentDevice ( );
67
- expect (currentDeviceKey, currentDevice.id );
68
- });
50
+ group ( 'Cognito GetDevice returns successfully' , () {
51
+ setUp (() async {
52
+ final mockIdp = MockCognitoIdentityProviderClient (
53
+ getDevice : () async => mockDeviceResponse,
54
+ forgetDevice : () async {},
55
+ );
56
+ plugin.stateMachine. addInstance < CognitoIdentityProviderClient >(mockIdp );
57
+ });
69
58
70
- test (
71
- 'should should throw a DeviceNotTrackedException when current device key is null' ,
72
- () async {
73
- await plugin.forgetDevice ();
74
- await expectLater (
75
- plugin.fetchCurrentDevice,
76
- throwsA (isA <DeviceNotTrackedException >()),
77
- );
78
- });
59
+ test (
60
+ 'should get the current device. current device id should be equal to the local device id' ,
61
+ () async {
62
+ final currentDeviceKey = await getDeviceKey ();
63
+ expect (currentDeviceKey, isNotNull);
64
+ final currentDevice = await plugin.fetchCurrentDevice ();
65
+ expect (currentDeviceKey, currentDevice.id);
66
+ });
79
67
80
- tearDown (() async {
81
- await plugin.close ();
68
+ test (
69
+ 'should should throw a DeviceNotTrackedException when current device key is null' ,
70
+ () async {
71
+ await plugin.forgetDevice ();
72
+ await expectLater (
73
+ plugin.fetchCurrentDevice,
74
+ throwsA (isA <DeviceNotTrackedException >()),
75
+ );
76
+ });
82
77
});
83
- });
84
78
85
- group ('fetchCurrentDevice AWSHttpException' , () {
86
- setUp (() async {
87
- secureStorage = MockSecureStorage ();
88
- seedStorage (
89
- secureStorage,
90
- userPoolKeys: userPoolKeys,
91
- identityPoolKeys: identityPoolKeys,
92
- deviceKeys: CognitoDeviceKeys (userPoolConfig, username),
93
- );
94
- plugin = AmplifyAuthCognitoDart (
95
- secureStorageFactory: (_) => secureStorage,
96
- );
97
- stateMachine = plugin.stateMachine;
98
- await plugin.configure (
99
- config: mockConfig,
100
- authProviderRepo: testAuthRepo,
101
- );
102
- final mockIdp = MockCognitoIdentityProviderClient (
103
- getDevice: () async => throw AWSHttpException (
104
- AWSHttpRequest .get (Uri .parse ('https://www.amazon.com' )),
105
- ),
106
- );
107
- stateMachine.addInstance <CognitoIdentityProviderClient >(mockIdp);
108
- repo = stateMachine.getOrCreate <DeviceMetadataRepository >();
109
- });
79
+ group ('Cognito GetDevice throws AWSHttpException' , () {
80
+ setUp (() async {
81
+ final mockIdp = MockCognitoIdentityProviderClient (
82
+ getDevice: () async => throw AWSHttpException (
83
+ AWSHttpRequest .get (Uri .parse ('https://aws.amazon.com/cognito/' )),
84
+ ),
85
+ );
86
+ plugin.stateMachine.addInstance <CognitoIdentityProviderClient >(mockIdp);
87
+ });
110
88
111
- test ('should throw a NetworkException' , () async {
112
- await expectLater (
113
- plugin.fetchCurrentDevice,
114
- throwsA (isA <NetworkException >()),
115
- );
89
+ test ('should throw a NetworkException' , () async {
90
+ await expectLater (
91
+ plugin.fetchCurrentDevice,
92
+ throwsA (isA <NetworkException >()),
93
+ );
94
+ });
116
95
});
117
96
118
97
tearDown (() async {
0 commit comments