-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: [#17] 회원가입 API, UseCase 테스트 작성
- Loading branch information
1 parent
46d33fd
commit 4127ef8
Showing
7 changed files
with
211 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
lib/feature/account/data/data_sources/dto/sign_up/request/sign_up_request_dto.mock.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
part of 'sign_up_request_dto.dart'; | ||
|
||
extension SignUpRequestDtoMock on SignUpRequestDto { | ||
static SignUpRequestDto mock() { | ||
return SignUpRequestDto( | ||
loginId: 'test@test.com', | ||
password: '123qwe!@', | ||
type: LoginType.email, | ||
gender: GenderType.man, | ||
name: '김땡땡', | ||
birthDate: DateTime.now(), | ||
cellPhoneNo: '01012345678', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
lib/feature/account/domain/entity/sign_up/request/sign_up_request_entity.mock.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
part of 'sign_up_request_entity.dart'; | ||
|
||
extension SignUpRequestEntityMock on SignUpRequestEntity { | ||
|
||
static SignUpRequestEntity mock() { | ||
return SignUpRequestEntity( | ||
loginId: const Email(value: 'test@test.com'), | ||
password: const Password('123qwe!@'), | ||
loginType: LoginType.email, | ||
gender: GenderType.man, | ||
name: const Name('김땡땡'), | ||
birthDate: const BirthDate('19930604'), | ||
phone: const Phone('01012345678'), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
test/feature/account/domain/usecase/sign_up/usecase_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:withu_app/core/core.dart'; | ||
import 'package:withu_app/feature/account/account.dart'; | ||
|
||
class MockAccountRepository extends Mock implements AccountRepository {} | ||
|
||
void main() { | ||
late MockAccountRepository mockRepo; | ||
late SignUpUseCase useCase; | ||
|
||
setUpAll(() { | ||
registerFallbackValue(SignUpRequestDtoMock.mock()); | ||
}); | ||
|
||
setUp(() { | ||
mockRepo = MockAccountRepository(); | ||
useCase = SignUpUseCaseImpl(accountRepo: mockRepo); | ||
}); | ||
|
||
group('회워 가입 UseCase 테스트', () { | ||
test('회원가입 성공', () async { | ||
/// Given | ||
final requestEntity = SignUpRequestEntityMock.mock(); | ||
final expectDto = SignUpResponseDtoMock.success(); | ||
|
||
when( | ||
() => mockRepo.signUp(dto: any(named: 'dto')), | ||
).thenAnswer( | ||
(_) async => ApiResponse.success(expectDto), | ||
); | ||
|
||
/// When | ||
final result = await useCase.exec(entity: requestEntity); | ||
|
||
/// Then | ||
expect(result, isA<SignUpResultEntity>()); | ||
expect(result.status, isTrue); | ||
verify(() => mockRepo.signUp(dto: any(named: 'dto'))).called(1); | ||
}); | ||
|
||
test('회원가입 실패', () async { | ||
/// Given | ||
final requestEntity = SignUpRequestEntityMock.mock(); | ||
final expectDto = SignUpResponseDtoMock.failure(); | ||
|
||
when( | ||
() => mockRepo.signUp(dto: any(named: 'dto')), | ||
).thenAnswer( | ||
(_) async => ApiResponse.success(expectDto), | ||
); | ||
|
||
/// When | ||
final result = await useCase.exec(entity: requestEntity); | ||
|
||
/// Then | ||
expect(result, isA<SignUpResultEntity>()); | ||
expect(result.status, isFalse); | ||
verify(() => mockRepo.signUp(dto: any(named: 'dto'))).called(1); | ||
}); | ||
|
||
test('서버에러', () async { | ||
/// Given | ||
final requestEntity = SignUpRequestEntityMock.mock(); | ||
final expectDto = FailResponse.error(); | ||
|
||
when( | ||
() => mockRepo.signUp(dto: any(named: 'dto')), | ||
).thenAnswer( | ||
(_) async => ApiResponse.fail(expectDto), | ||
); | ||
|
||
/// When | ||
final result = await useCase.exec(entity: requestEntity); | ||
|
||
/// Then | ||
expect(result, isA<SignUpResultEntity>()); | ||
expect(result.status, isFalse); | ||
expect(result.message, StringRes.serverError.tr); | ||
verify(() => mockRepo.signUp(dto: any(named: 'dto'))).called(1); | ||
}); | ||
}); | ||
} |