-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f48086
commit 55affd9
Showing
8 changed files
with
225 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import 'package:dantex/src/data/authentication/entity/dante_user.dart'; | |
import 'package:dantex/src/data/authentication/firebase_authentication_repository.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:google_sign_in/google_sign_in.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
|
||
|
@@ -15,20 +14,14 @@ import 'firebase_authentication_repository_test.mocks.dart'; | |
UserCredential, | ||
User, | ||
UserInfo, | ||
GoogleSignIn, | ||
GoogleSignInAccount, | ||
GoogleSignInAuthentication, | ||
GoogleAuthProvider, | ||
AuthCredential, | ||
]) | ||
void main() { | ||
const String testEmail = '[email protected]'; | ||
const String testPassword = 'password'; | ||
|
||
test('Get account returns DanteUser', () async { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final fbAuthRepo = FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final fbAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
final User user = MockUser(); | ||
final UserInfo userInfo = MockUserInfo(); | ||
final DanteUser danteUser = DanteUser( | ||
|
@@ -63,33 +56,18 @@ void main() { | |
group('Login', () { | ||
test('Login with Google returns user credential on success', () async { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
final userCred = MockUserCredential(); | ||
final googleSignInAccount = MockGoogleSignInAccount(); | ||
final googleSignInAuthentication = MockGoogleSignInAuthentication(); | ||
when(googleSignIn.signIn()).thenAnswer((_) async => googleSignInAccount); | ||
when(googleSignInAccount.authentication) | ||
.thenAnswer((_) async => googleSignInAuthentication); | ||
when(googleSignInAuthentication.accessToken).thenReturn('accessToken'); | ||
when(googleSignInAuthentication.idToken).thenReturn('idToken'); | ||
|
||
when(fbAuth.signInWithCredential(any)).thenAnswer((_) async => userCred); | ||
when(fbAuth.signInWithProvider(any)).thenAnswer((_) async => userCred); | ||
|
||
expect(await firebaseAuthRepo.loginWithGoogle(), userCred); | ||
verify(fbAuth.signInWithCredential(any)).called(1); | ||
verify(googleSignIn.signIn()).called(1); | ||
verify(googleSignInAccount.authentication).called(1); | ||
verify(googleSignInAuthentication.accessToken).called(1); | ||
verify(googleSignInAuthentication.idToken).called(1); | ||
verify(fbAuth.signInWithProvider(any)).called(1); | ||
}); | ||
|
||
test('Login anonymously returns User Credential on success', () async { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
final userCred = MockUserCredential(); | ||
|
||
when(fbAuth.signInAnonymously()).thenAnswer((_) async => userCred); | ||
|
@@ -100,9 +78,7 @@ void main() { | |
|
||
test('Login with email returns User Credential on success', () async { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
final userCred = MockUserCredential(); | ||
|
||
when( | ||
|
@@ -130,9 +106,7 @@ void main() { | |
|
||
test('logout returns void on success', () async { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
|
||
when(fbAuth.signOut()).thenAnswer((_) async => Future<void>); | ||
|
||
|
@@ -144,9 +118,7 @@ void main() { | |
'fetchSignInMethodsForEmail maps sign in methods to AuthenticationSource', | ||
() async { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
|
||
when(fbAuth.fetchSignInMethodsForEmail(testEmail)) | ||
.thenAnswer((_) async => ['google.com', 'password', 'apple.com']); | ||
|
@@ -165,9 +137,7 @@ void main() { | |
|
||
test('Create mail account returns User Credential on success', () async { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
final userCred = MockUserCredential(); | ||
|
||
when( | ||
|
@@ -195,9 +165,7 @@ void main() { | |
test('Upgrade anonymous account returns User Credential on success', | ||
() async { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
final user = MockUser(); | ||
final userCred = MockUserCredential(); | ||
|
||
|
@@ -222,9 +190,7 @@ void main() { | |
'Upgrade anonymous account throws FirebaseAuthException error when user not found', | ||
() async { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
|
||
when( | ||
fbAuth.currentUser, | ||
|
@@ -241,9 +207,7 @@ void main() { | |
|
||
test('Update user password returns void on success', () { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
final user = MockUser(); | ||
|
||
when(fbAuth.currentUser).thenReturn(user); | ||
|
@@ -259,9 +223,7 @@ void main() { | |
'Upgrade password throws FirebaseAuthException error when user not found', | ||
() async { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
|
||
when( | ||
fbAuth.currentUser, | ||
|
@@ -277,9 +239,7 @@ void main() { | |
|
||
test('Send password reset request returns void on success', () { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
|
||
when(fbAuth.sendPasswordResetEmail(email: testEmail)) | ||
.thenAnswer((_) async => Future<void>); | ||
|
@@ -290,9 +250,7 @@ void main() { | |
|
||
test('Delete user returns void on success', () async { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
final User user = MockUser(); | ||
|
||
when(fbAuth.currentUser).thenReturn(user); | ||
|
@@ -305,9 +263,7 @@ void main() { | |
|
||
test('Auth state changes returns DanteUser', () { | ||
final fbAuth = MockFirebaseAuth(); | ||
final googleSignIn = MockGoogleSignIn(); | ||
final firebaseAuthRepo = | ||
FirebaseAuthenticationRepository(fbAuth, googleSignIn); | ||
final firebaseAuthRepo = FirebaseAuthenticationRepository(fbAuth); | ||
final User user = MockUser(); | ||
final UserInfo userInfo = MockUserInfo(); | ||
final DanteUser danteUser = DanteUser( | ||
|
Oops, something went wrong.