feat(authentication)!: rename package

This commit is contained in:
2022-04-19 19:34:04 +02:00
parent 22e0aeeeed
commit c70446e2c4
148 changed files with 7788 additions and 0 deletions
@@ -0,0 +1,232 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:bloc_test/bloc_test.dart';
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
class MockAuthenticationRepository extends Mock
implements AuthenticationRepositoryInterface {}
class MockAuthenticationCubit extends Mock implements AuthenticationCubit {}
void main() {
const String invalidEmailString = 'invalid';
const Email invalidEmail = Email.dirty(invalidEmailString);
const String validEmailString = 'test@gmail.com';
const Email validEmail = Email.dirty(validEmailString);
const String invalidPasswordString = 'invalid';
const Password invalidPassword = Password.dirty(invalidPasswordString);
const String validPasswordString = 't0pS3cret1234';
const Password validPassword = Password.dirty(validPasswordString);
group('SignInCubit', () {
late AuthenticationRepositoryInterface authenticationRepository;
late AuthenticationCubit authenticationCubit;
setUp(() {
authenticationRepository = MockAuthenticationRepository();
authenticationCubit = MockAuthenticationCubit();
when(
() => authenticationRepository.signInWithEmailAndPassword(
email: any(named: 'email'),
password: any(named: 'password'),
),
).thenAnswer((_) async {});
when(
() => authenticationCubit.start(),
).thenReturn(true);
});
test('initial state is SignInState', () {
expect(
SignInCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
).state,
const SignInState(),
);
});
group('emailChanged', () {
blocTest<SignInCubit, SignInState>(
'emits [invalid] when email/password are invalid',
build: () => SignInCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
),
act: (SignInCubit cubit) => cubit.emailChanged(invalidEmailString),
expect: () => const <SignInState>[
SignInState(email: invalidEmail, status: FormStatus.invalid),
],
);
blocTest<SignInCubit, SignInState>(
'emits [valid] when email/password are valid',
build: () => SignInCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
),
seed: () => const SignInState(password: validPassword),
act: (SignInCubit cubit) => cubit.emailChanged(validEmailString),
expect: () => const <SignInState>[
SignInState(
email: validEmail,
password: validPassword,
status: FormStatus.valid,
),
],
);
});
group('passwordChanged', () {
blocTest<SignInCubit, SignInState>(
'emits [invalid] when email/password are invalid',
build: () => SignInCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
),
act: (SignInCubit cubit) =>
cubit.passwordChanged(invalidPasswordString),
expect: () => const <SignInState>[
SignInState(
password: invalidPassword,
status: FormStatus.invalid,
),
],
);
blocTest<SignInCubit, SignInState>(
'emits [valid] when email/password are valid',
build: () => SignInCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
),
seed: () => const SignInState(email: validEmail),
act: (SignInCubit cubit) => cubit.passwordChanged(validPasswordString),
expect: () => const <SignInState>[
SignInState(
email: validEmail,
password: validPassword,
status: FormStatus.valid,
),
],
);
});
group('logInWithCredentials', () {
blocTest<SignInCubit, SignInState>(
'does nothing when status is not validated',
build: () => SignInCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
),
act: (SignInCubit cubit) => cubit.signInWithEmailAndPassword(),
expect: () => const <SignInState>[],
);
blocTest<SignInCubit, SignInState>(
'calls signInWithEmailAndPassword with correct email/password',
build: () => SignInCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
),
seed: () => const SignInState(
status: FormStatus.valid,
email: validEmail,
password: validPassword,
),
act: (SignInCubit cubit) => cubit.signInWithEmailAndPassword(),
verify: (_) {
verify(
() => authenticationRepository.signInWithEmailAndPassword(
email: validEmailString,
password: validPasswordString,
),
).called(1);
},
);
blocTest<SignInCubit, SignInState>(
'emits [submissionInProgress, submissionSuccess] '
'when signInWithEmailAndPassword succeeds',
build: () => SignInCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
),
seed: () => const SignInState(
status: FormStatus.valid,
email: validEmail,
password: validPassword,
),
act: (SignInCubit cubit) => cubit.signInWithEmailAndPassword(),
expect: () => const <SignInState>[
SignInState(
status: FormStatus.submissionInProgress,
email: validEmail,
password: validPassword,
),
SignInState(
status: FormStatus.submissionSuccess,
email: validEmail,
password: validPassword,
)
],
);
blocTest<SignInCubit, SignInState>(
'emits [submissionInProgress, submissionFailure] '
'when signInWithEmailAndPassword fails',
setUp: () {
when(
() => authenticationRepository.signInWithEmailAndPassword(
email: any(named: 'email'),
password: any(named: 'password'),
),
).thenThrow(Exception('oops'));
},
build: () => SignInCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
),
seed: () => const SignInState(
status: FormStatus.valid,
email: validEmail,
password: validPassword,
),
act: (SignInCubit cubit) => cubit.signInWithEmailAndPassword(),
expect: () => const <SignInState>[
SignInState(
status: FormStatus.submissionInProgress,
email: validEmail,
password: validPassword,
),
SignInState(
status: FormStatus.submissionFailure,
email: validEmail,
password: validPassword,
)
],
);
});
});
}
@@ -0,0 +1,54 @@
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
const Email email = Email.dirty('email');
const Password password = Password.dirty('password');
group('SignInState', () {
test('supports value comparisons', () {
expect(const SignInState(), const SignInState());
});
test('returns same object when no properties are passed', () {
expect(const SignInState().copyWith(), const SignInState());
});
test('returns object with updated status when status is passed', () {
expect(
const SignInState().copyWith(status: FormStatus.pure),
const SignInState(),
);
});
test('returns object with updated email when email is passed', () {
expect(
const SignInState().copyWith(email: email),
const SignInState(email: email),
);
});
test('returns object with updated password when password is passed', () {
expect(
const SignInState().copyWith(password: password),
const SignInState(password: password),
);
});
});
}