@@ -31,92 +31,86 @@ void main() {
31
31
return secrets? .deviceKey;
32
32
}
33
33
34
- group (
35
- 'fetchCurrentDevice expected return value and DeviceNotTrackedException' ,
36
- () {
37
- setUp (() async {
38
- secureStorage = MockSecureStorage ();
39
- seedStorage (
40
- secureStorage,
41
- userPoolKeys: userPoolKeys,
42
- identityPoolKeys: identityPoolKeys,
43
- deviceKeys: CognitoDeviceKeys (userPoolConfig, username),
44
- );
45
- plugin = AmplifyAuthCognitoDart (
46
- secureStorageFactory: (_) => secureStorage,
47
- );
48
- stateMachine = plugin.stateMachine;
49
- await plugin.configure (
50
- config: mockConfig,
51
- authProviderRepo: testAuthRepo,
52
- );
53
- final mockIdp = MockCognitoIdentityProviderClient (
54
- getDevice: () async => mockDeviceResponse,
55
- forgetDevice: () async {},
56
- );
57
- stateMachine.addInstance <CognitoIdentityProviderClient >(mockIdp);
58
- repo = stateMachine.getOrCreate <DeviceMetadataRepository >();
59
- });
34
+ setUp (() async {
35
+ secureStorage = MockSecureStorage ();
36
+ seedStorage (
37
+ secureStorage,
38
+ userPoolKeys: userPoolKeys,
39
+ identityPoolKeys: identityPoolKeys,
40
+ deviceKeys: CognitoDeviceKeys (userPoolConfig, username),
41
+ );
42
+ plugin = AmplifyAuthCognitoDart (
43
+ secureStorageFactory: (_) => secureStorage,
44
+ );
45
+ stateMachine = plugin.stateMachine;
46
+ await plugin.configure (
47
+ config: mockConfig,
48
+ authProviderRepo: testAuthRepo,
49
+ );
50
+ repo = stateMachine.getOrCreate <DeviceMetadataRepository >();
51
+ });
60
52
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
- });
53
+ tearDown (() async {
54
+ await plugin.close ();
55
+ });
69
56
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
- });
57
+ group ( 'fetchCurrentDevice' , () {
58
+ group ( 'expected return value and DeviceNotTrackedException' , () {
59
+ setUp ( () async {
60
+ final mockIdp = MockCognitoIdentityProviderClient (
61
+ getDevice : () async => mockDeviceResponse,
62
+ forgetDevice : () async {} ,
63
+ );
64
+ stateMachine. addInstance < CognitoIdentityProviderClient >(mockIdp );
65
+ });
79
66
80
- tearDown (() async {
81
- await plugin.close ();
67
+ test (
68
+ 'should get the current device. current device id should be equal to the local device id' ,
69
+ () async {
70
+ final currentDeviceKey = await getDeviceKey ();
71
+ expect (currentDeviceKey, isNotNull);
72
+ final currentDevice = await plugin.fetchCurrentDevice ();
73
+ expect (currentDeviceKey, currentDevice.id);
74
+ });
82
75
});
83
- });
84
76
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
- });
77
+ group ('DeviceNotTrackedException' , () {
78
+ setUp (() async {
79
+ final mockIdp = MockCognitoIdentityProviderClient (
80
+ getDevice: () async => mockDeviceResponse,
81
+ forgetDevice: () async {},
82
+ );
83
+ stateMachine.addInstance <CognitoIdentityProviderClient >(mockIdp);
84
+ });
110
85
111
- test ('should throw a NetworkException' , () async {
112
- await expectLater (
113
- plugin.fetchCurrentDevice,
114
- throwsA (isA <NetworkException >()),
115
- );
86
+ test (
87
+ 'should throw a DeviceNotTrackedException when current device key is null' ,
88
+ () async {
89
+ await plugin.forgetDevice ();
90
+ await expectLater (
91
+ plugin.fetchCurrentDevice,
92
+ throwsA (isA <DeviceNotTrackedException >()),
93
+ );
94
+ });
116
95
});
117
96
118
- tearDown (() async {
119
- await plugin.close ();
97
+ group ('AWSHttpException' , () {
98
+ setUp (() async {
99
+ final mockIdp = MockCognitoIdentityProviderClient (
100
+ getDevice: () async => throw AWSHttpException (
101
+ AWSHttpRequest .get (Uri .parse ('https://aws.amazon.com/cognito/' )),
102
+ ),
103
+ );
104
+ stateMachine.addInstance <CognitoIdentityProviderClient >(mockIdp);
105
+ });
106
+
107
+ test ('should convert AWSHttpException to and throw a NetworkException' ,
108
+ () async {
109
+ await expectLater (
110
+ plugin.fetchCurrentDevice,
111
+ throwsA (isA <NetworkException >()),
112
+ );
113
+ });
120
114
});
121
115
});
122
116
}
0 commit comments