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,266 @@
// 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('SignUpCubit', () {
late AuthenticationRepositoryInterface authenticationRepository;
late AuthenticationCubit authenticationCubit;
setUp(() {
authenticationRepository = MockAuthenticationRepository();
authenticationCubit = MockAuthenticationCubit();
when(
() => authenticationRepository.signUp(
email: any(named: 'email'),
password: any(named: 'password'),
),
).thenAnswer((_) async {
return 'uid';
});
when(
() => authenticationCubit.start(),
).thenReturn(true);
when(
() => authenticationCubit.stop(),
).thenReturn(true);
});
test('initial state is SignUpState', () {
expect(
SignUpCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
entries: FormData.empty(),
).state,
SignUpState(data: FormData.empty()),
);
});
group('emailChanged', () {
blocTest<SignUpCubit, SignUpState>(
'emits [invalid] when email/password are invalid',
build: () => SignUpCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
entries: FormData.empty(),
),
act: (SignUpCubit cubit) => cubit.emailChanged(invalidEmailString),
expect: () => <SignUpState>[
SignUpState(
email: invalidEmail,
status: FormStatus.invalid,
data: FormData.empty(),
),
],
);
blocTest<SignUpCubit, SignUpState>(
'emits [valid] when email/password are valid',
build: () => SignUpCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
entries: FormData.empty(),
),
seed: () => SignUpState(
password: validPassword,
data: FormData.empty(),
),
act: (SignUpCubit cubit) => cubit.emailChanged(validEmailString),
expect: () => <SignUpState>[
SignUpState(
email: validEmail,
password: validPassword,
status: FormStatus.valid,
data: FormData.empty(),
),
],
);
});
group('passwordChanged', () {
blocTest<SignUpCubit, SignUpState>(
'emits [invalid] when email/password are invalid',
build: () => SignUpCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
entries: FormData.empty(),
),
act: (SignUpCubit cubit) =>
cubit.passwordChanged(invalidPasswordString),
expect: () => <SignUpState>[
SignUpState(
password: invalidPassword,
status: FormStatus.invalid,
data: FormData.empty(),
),
],
);
blocTest<SignUpCubit, SignUpState>(
'emits [valid] when email/password are valid',
build: () => SignUpCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
entries: FormData.empty(),
),
seed: () => SignUpState(
email: validEmail,
data: FormData.empty(),
),
act: (SignUpCubit cubit) => cubit.passwordChanged(validPasswordString),
expect: () => <SignUpState>[
SignUpState(
email: validEmail,
password: validPassword,
status: FormStatus.valid,
data: FormData.empty(),
),
],
);
});
group('signUpFormSubmitted', () {
blocTest<SignUpCubit, SignUpState>(
'does nothing when status is not validated',
build: () => SignUpCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
entries: FormData.empty(),
),
act: (SignUpCubit cubit) => cubit.signUpFormSubmitted(),
expect: () => const <SignUpState>[],
);
blocTest<SignUpCubit, SignUpState>(
'calls signUp with correct email/password/confirmedPassword',
build: () => SignUpCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
entries: FormData.empty(),
),
seed: () => SignUpState(
status: FormStatus.valid,
email: validEmail,
password: validPassword,
data: FormData.empty(),
),
act: (SignUpCubit cubit) => cubit.signUpFormSubmitted(),
verify: (_) {
verify(
() => authenticationRepository.signUp(
email: validEmailString,
password: validPasswordString,
),
).called(1);
},
);
blocTest<SignUpCubit, SignUpState>(
'emits [submissionInProgress, submissionSuccess] '
'when signUp succeeds',
build: () => SignUpCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
entries: FormData.empty(),
),
seed: () => SignUpState(
status: FormStatus.valid,
email: validEmail,
password: validPassword,
data: FormData.empty(),
),
act: (SignUpCubit cubit) => cubit.signUpFormSubmitted(),
expect: () => <SignUpState>[
SignUpState(
status: FormStatus.submissionInProgress,
email: validEmail,
password: validPassword,
data: FormData.empty(),
),
SignUpState(
status: FormStatus.submissionSuccess,
email: validEmail,
password: validPassword,
data: FormData.empty(),
)
],
);
blocTest<SignUpCubit, SignUpState>(
'emits [submissionInProgress, submissionFailure] '
'when signUp fails',
setUp: () {
when(
() => authenticationRepository.signUp(
email: any(named: 'email'),
password: any(named: 'password'),
),
).thenThrow(Exception('oops'));
},
build: () => SignUpCubit(
authenticationRepository: authenticationRepository,
authenticationCubit: authenticationCubit,
entries: FormData.empty(),
),
seed: () => SignUpState(
status: FormStatus.valid,
email: validEmail,
password: validPassword,
data: FormData.empty(),
),
act: (SignUpCubit cubit) => cubit.signUpFormSubmitted(),
expect: () => <SignUpState>[
SignUpState(
status: FormStatus.submissionInProgress,
email: validEmail,
password: validPassword,
data: FormData.empty(),
),
SignUpState(
status: FormStatus.submissionFailure,
email: validEmail,
password: validPassword,
data: FormData.empty(),
)
],
);
});
});
}
@@ -0,0 +1,112 @@
// 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 String passwordString = 'password';
const Password password = Password.dirty(passwordString);
group('SignUpState', () {
test('supports value comparisons', () {
expect(
SignUpState(
data: FormData.empty(),
),
SignUpState(
data: FormData.empty(),
),
);
});
test('returns same object when no properties are passed', () {
expect(
SignUpState(
data: FormData.empty(),
).copyWith(),
SignUpState(
data: FormData.empty(),
),
);
});
test('returns object with updated status when status is passed', () {
expect(
SignUpState(
data: FormData.empty(),
).copyWith(status: FormStatus.pure),
SignUpState(
data: FormData.empty(),
),
);
});
test('returns object with updated email when email is passed', () {
expect(
SignUpState(
data: FormData.empty(),
).copyWith(email: email),
SignUpState(
email: email,
data: FormData.empty(),
),
);
});
test('returns object with updated password when password is passed', () {
expect(
SignUpState(
data: FormData.empty(),
).copyWith(password: password),
SignUpState(
password: password,
data: FormData.empty(),
),
);
});
test(
'returns object with updated data'
' when data is passed', () {
expect(
SignUpState(
data: FormData.empty(),
).copyWith(
data: const FormData(
[
FormEntry(
'field',
Name.pure(),
),
],
),
),
const SignUpState(
data: FormData(
[
FormEntry(
'field',
Name.pure(),
),
],
),
),
);
});
});
}