@@ -240,6 +240,45 @@ void main() {
240
240
await expectLater (Amplify .Auth .rememberDevice (), completes);
241
241
});
242
242
243
+ asyncTest ('fetchCurrentDevice returns the current device' , (_) async {
244
+ await expectLater (Amplify .Auth .fetchCurrentDevice (), completes);
245
+ final currentTestDevice = await Amplify .Auth .fetchCurrentDevice ();
246
+ final currentDeviceKey = await getDeviceKey ();
247
+ expect (currentDeviceKey, currentTestDevice.id);
248
+ });
249
+
250
+ asyncTest (
251
+ 'The device from fetchCurrentDevice isnt equal to another device.' ,
252
+ (_) async {
253
+ final previousDeviceKey = await getDeviceKey ();
254
+ await signOutUser ();
255
+ await deleteDevice (cognitoUsername, previousDeviceKey! );
256
+ await signIn ();
257
+ final newCurrentTestDevice = await Amplify .Auth .fetchCurrentDevice ();
258
+ expect (newCurrentTestDevice.id, isNot (previousDeviceKey));
259
+ });
260
+
261
+ asyncTest (
262
+ 'fetchCurrentDevice throws a DeviceNotTrackedException when device is forgotton.' ,
263
+ (_) async {
264
+ expect (await getDeviceState (), DeviceState .remembered);
265
+ await Amplify .Auth .forgetDevice ();
266
+ await expectLater (
267
+ Amplify .Auth .fetchCurrentDevice,
268
+ throwsA (isA <DeviceNotTrackedException >()),
269
+ );
270
+ });
271
+
272
+ asyncTest (
273
+ 'fetchCurrentDevice throws a SignedOutException when device signs out.' ,
274
+ (_) async {
275
+ await signOutUser ();
276
+ await expectLater (
277
+ Amplify .Auth .fetchCurrentDevice,
278
+ throwsA (isA <SignedOutException >()),
279
+ );
280
+ });
281
+
243
282
asyncTest ('forgetDevice stops tracking' , (_) async {
244
283
expect (await getDeviceState (), DeviceState .remembered);
245
284
await Amplify .Auth .forgetDevice ();
0 commit comments