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,99 @@
// 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 MockUser extends Mock implements UserInterface {}
void main() {
group('AuthenticationCubit', () {
final MockUser user = MockUser();
late AuthenticationRepositoryInterface authenticationRepository;
setUp(() {
authenticationRepository = MockAuthenticationRepository();
when(() => authenticationRepository.user).thenAnswer(
(_) => const Stream.empty(),
);
when(
() => authenticationRepository.currentUser,
).thenReturn(const UserFirebase.empty());
});
test('initial state is unknown', () {
expect(
AuthenticationCubit(authenticationRepository: authenticationRepository)
.state,
const AuthenticationState.unknown(),
);
});
group('UserChanged', () {
blocTest<AuthenticationCubit, AuthenticationState>(
'emits authenticated when user is not empty',
setUp: () {
when(() => user.isNotEmpty).thenReturn(true);
when(() => authenticationRepository.user).thenAnswer(
(_) => Stream.value(user),
);
},
build: () => AuthenticationCubit(
authenticationRepository: authenticationRepository,
)..init(),
seed: () => const AuthenticationState.unknown(),
expect: () => [AuthenticationState.authenticated(user, null)],
);
blocTest<AuthenticationCubit, AuthenticationState>(
'emits unauthenticated when user is empty',
setUp: () {
when(() => authenticationRepository.user).thenAnswer(
(_) => Stream.value(const UserFirebase.empty()),
);
},
build: () => AuthenticationCubit(
authenticationRepository: authenticationRepository,
)..init(),
seed: () => const AuthenticationState.unknown(),
expect: () => [const AuthenticationState.unauthenticated()],
);
});
group('LogoutRequested', () {
blocTest<AuthenticationCubit, AuthenticationState>(
'invokes signOut',
setUp: () {
when(
() => authenticationRepository.signOut(),
).thenAnswer((_) async {});
},
build: () => AuthenticationCubit(
authenticationRepository: authenticationRepository,
),
act: (AuthenticationCubit cubit) => cubit.logOut(),
verify: (_) {
verify(() => authenticationRepository.signOut()).called(1);
},
);
});
});
}
@@ -0,0 +1,43 @@
// 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';
import 'package:mocktail/mocktail.dart';
class MockUser extends Mock implements UserInterface {}
void main() {
group('AuthenticationState', () {
group('unauthenticated', () {
test('has correct status', () {
const AuthenticationState state = AuthenticationState.unauthenticated();
expect(state.status, AuthenticationStatus.unauthenticated);
expect(state.user, null);
});
});
group('authenticated', () {
test('has correct status', () {
final MockUser user = MockUser();
final AuthenticationState state =
AuthenticationState.authenticated(user, null);
expect(state.status, AuthenticationStatus.authenticated);
expect(state.user, user);
});
});
});
}