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/#10 sign out setting use case #71

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion lib/domain/user/repository/user_auth_repository.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
abstract interface class UserAuthRepository {

Future<bool> signOutSetting({required String email});
}
14 changes: 14 additions & 0 deletions lib/domain/user/use_case/sign_out_setting_use_case.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:weaco/domain/user/repository/user_auth_repository.dart';

class SignOutSettingUseCase {
final UserAuthRepository _userAuthRepository;

SignOutSettingUseCase({
required UserAuthRepository userAuthRepository,
}) : _userAuthRepository = userAuthRepository;

/// 설정 화면의 회월 탈퇴를 위한 Use Case
Future<bool> execute({required String email}) async {
return await _userAuthRepository.signOutSetting(email: email);
}
}
75 changes: 75 additions & 0 deletions test/domain/user/use_case/sign_out_setting_use_case_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:weaco/domain/user/model/user_profile.dart';
import 'package:weaco/domain/user/use_case/sign_out_setting_use_case.dart';

import '../../../mock/data/user/repository/mock_sign_out_setting_case_repository_impl.dart';

void main() {
group('SignOutSettingUseCase 클래스', () {
final mockSignOutSettingRepositoryImpl = MockSignOutSettingRepositoryImpl();
final SignOutSettingUseCase useCase = SignOutSettingUseCase(
userAuthRepository: mockSignOutSettingRepositoryImpl);

group('signOutSetting 메서드는', () {
setUp(() => mockSignOutSettingRepositoryImpl.initMockData());

test('유저 정보가 없을 경우, 회원 탈퇴에 실패한다.', () async {
// Given
const bool expectedResult = false;
String email = '[email protected]';

// When
final result = await useCase.execute(email: email);

// Then
expect(result, expectedResult);
});

test('유저 정보가 일치 하지 않을 경우, 회원 탈퇴에 실패한다.', () async {
// Given
const bool expectedResult = false;
String email = '[email protected]';
UserProfile? profile = UserProfile(
email: '[email protected]',
nickname: 'nickName',
gender: 0,
profileImagePath:
'https://health.chosun.com/site/data/img_dir/2024/01/22/2024012201607_0.jpg',
feedCount: 0,
createdAt: DateTime.parse('2024-05-01 14:27:00'),
);

mockSignOutSettingRepositoryImpl.addProfile(profile: profile);

// When
final result = await useCase.execute(email: email);

// Then
expect(result, expectedResult);
});

test('유저 정보가 일치할 경우, 회원 탈퇴에 성공한다.', () async {
// Given
const bool expectedResult = true;
String email = '[email protected]';
UserProfile? profile = UserProfile(
email: '[email protected]',
nickname: 'nickName',
gender: 0,
profileImagePath:
'https://health.chosun.com/site/data/img_dir/2024/01/22/2024012201607_0.jpg',
feedCount: 0,
createdAt: DateTime.parse('2024-05-01 14:27:00'),
);

mockSignOutSettingRepositoryImpl.addProfile(profile: profile);

// When
final result = await useCase.execute(email: email);

// Then
expect(result, expectedResult);
});
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:weaco/domain/user/model/user_profile.dart';
import 'package:weaco/domain/user/repository/user_auth_repository.dart';

class MockSignOutSettingRepositoryImpl implements UserAuthRepository {
final Map<String, UserProfile> _fakeUserProfileMap = {};
bool isSignOut = false;

@override
Future<bool> signOutSetting({required String email}) async {
if ( _fakeUserProfileMap[email] != null) {
isSignOut = true;
}
return isSignOut;
}

void addProfile({required UserProfile profile}) {
_fakeUserProfileMap[profile.email] = profile;
}

void initMockData() {
isSignOut = false;
}
}