Skip to content

Commit 060f587

Browse files
committed
feat: added integration test suite
1 parent fb001b4 commit 060f587

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

packages/auth/amplify_auth_cognito/example/integration_test/device_tracking_test.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,45 @@ void main() {
240240
await expectLater(Amplify.Auth.rememberDevice(), completes);
241241
});
242242

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+
243282
asyncTest('forgetDevice stops tracking', (_) async {
244283
expect(await getDeviceState(), DeviceState.remembered);
245284
await Amplify.Auth.forgetDevice();

0 commit comments

Comments
 (0)