Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat (Auth): Integration Tests for fetchCurrentDevice API #5072

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,45 @@ void main() {
await expectLater(Amplify.Auth.rememberDevice(), completes);
});

asyncTest('fetchCurrentDevice returns the current device', (_) async {
await expectLater(Amplify.Auth.fetchCurrentDevice(), completes);
final currentTestDevice = await Amplify.Auth.fetchCurrentDevice();
final currentDeviceKey = await getDeviceKey();
expect(currentDeviceKey, currentTestDevice.id);
});

asyncTest(
'The device from fetchCurrentDevice isnt equal to another device.',
(_) async {
final previousDeviceKey = await getDeviceKey();
await signOutUser();
await deleteDevice(cognitoUsername, previousDeviceKey!);
await signIn();
final newCurrentTestDevice = await Amplify.Auth.fetchCurrentDevice();
expect(newCurrentTestDevice.id, isNot(previousDeviceKey));
});

asyncTest(
'fetchCurrentDevice throws a DeviceNotTrackedException when device is forgotten.',
(_) async {
expect(await getDeviceState(), DeviceState.remembered);
await Amplify.Auth.forgetDevice();
await expectLater(
Amplify.Auth.fetchCurrentDevice,
throwsA(isA<DeviceNotTrackedException>()),
);
});

asyncTest(
'fetchCurrentDevice throws a SignedOutException when device signs out.',
(_) async {
await signOutUser();
await expectLater(
Amplify.Auth.fetchCurrentDevice,
throwsA(isA<SignedOutException>()),
);
});

asyncTest('forgetDevice stops tracking', (_) async {
expect(await getDeviceState(), DeviceState.remembered);
await Amplify.Auth.forgetDevice();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ Future<List<AuthUserAttribute>> fetchUserAttributes() async {
return Amplify.Auth.fetchUserAttributes();
}

Future<AuthDevice> fetchCurrentDevice() async {
return Amplify.Auth.fetchCurrentDevice();
}

Future<List<AuthDevice>> fetchDevices() async {
return Amplify.Auth.fetchDevices();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ class AmplifyAuthCognitoStub extends AuthPluginInterface
);
}

@override
Future<AuthDevice> fetchCurrentDevice() async {
throw UnimplementedError(
'fetchCurrentDevice is not implemented.',
);
}

@override
Future<void> forgetDevice([AuthDevice? device]) async {
throw UnimplementedError(
Expand All @@ -391,7 +398,6 @@ class AmplifyAuthCognitoStub extends AuthPluginInterface
}

class MockCognitoUser {

factory MockCognitoUser({
required String username,
required String password,
Expand Down
Loading