diff --git a/lib/domain/user/repository/user_auth_repository.dart b/lib/domain/user/repository/user_auth_repository.dart index 8106a495..b4a2a5ca 100644 --- a/lib/domain/user/repository/user_auth_repository.dart +++ b/lib/domain/user/repository/user_auth_repository.dart @@ -1,3 +1,3 @@ abstract interface class UserAuthRepository { - + Future signOutSetting({required String email}); } \ No newline at end of file diff --git a/lib/domain/user/use_case/sign_out_setting_use_case.dart b/lib/domain/user/use_case/sign_out_setting_use_case.dart new file mode 100644 index 00000000..41faed4e --- /dev/null +++ b/lib/domain/user/use_case/sign_out_setting_use_case.dart @@ -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 execute({required String email}) async { + return await _userAuthRepository.signOutSetting(email: email); + } +} diff --git a/test/domain/user/use_case/sign_out_setting_use_case_test.dart b/test/domain/user/use_case/sign_out_setting_use_case_test.dart new file mode 100644 index 00000000..eba65e4d --- /dev/null +++ b/test/domain/user/use_case/sign_out_setting_use_case_test.dart @@ -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 = 'wrong@email.com'; + + // When + final result = await useCase.execute(email: email); + + // Then + expect(result, expectedResult); + }); + + test('유저 정보가 일치 하지 않을 경우, 회원 탈퇴에 실패한다.', () async { + // Given + const bool expectedResult = false; + String email = 'wrong@email.com'; + UserProfile? profile = UserProfile( + email: 'mock@email.com', + 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 = 'mock@email.com'; + UserProfile? profile = UserProfile( + email: 'mock@email.com', + 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); + }); + }); + }); +} diff --git a/test/mock/data/user/repository/mock_sign_out_setting_case_repository_impl.dart b/test/mock/data/user/repository/mock_sign_out_setting_case_repository_impl.dart new file mode 100644 index 00000000..bd878db2 --- /dev/null +++ b/test/mock/data/user/repository/mock_sign_out_setting_case_repository_impl.dart @@ -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 _fakeUserProfileMap = {}; + bool isSignOut = false; + + @override + Future 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; + } +}