Skip to content

Commit

Permalink
Merge pull request #22 from f-lab-edu/test/login
Browse files Browse the repository at this point in the history
�[#16] 로그인 기능 테스트 코드 작성
  • Loading branch information
Younggun-Kim authored Nov 24, 2024
2 parents 7df14b7 + e25111d commit c8896ae
Show file tree
Hide file tree
Showing 48 changed files with 1,387 additions and 344 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ app.*.map.json
# Freezed generated files
*.freezed.dart
*.g.dart


# Mockito generated file
*.mocks.dart
11 changes: 5 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ repos:
type: [ dart ]
files: lib/.*\.dart$

# - id: dart-format
# name: dart-format
# entry: bash -c 'dart format "$@"'
# language: system
# type: [ dart ]
# files: lib/.*\.dart$
- id: flutter-test
name: flutter-test
entry: bash -c 'flutter test'
language: system
type: [ dart ]
130 changes: 65 additions & 65 deletions ios/Runner.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions lib/core/network/api_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ extension ApiResponseExt<T> on ApiResponse<T> {
success: (T data) => data,
orElse: () => null,
);

/// Fail Data 가져오기
FailResponse? get failData => maybeWhen(
fail: (FailResponse failResponse) => failResponse,
orElse: () => null,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:pretty_dio_logger/pretty_dio_logger.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:withu_app/feature/account/account.dart';

class API {
class DioNetwork {
final String url = 'https://example.com';

late final _dio = Dio(BaseOptions(
Expand Down
4 changes: 2 additions & 2 deletions lib/core/network/mock_api.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:http_mock_adapter/http_mock_adapter.dart';

import 'api.dart';
import 'dio_network.dart';

mixin MockAPI on API {
mixin MockAPI on DioNetwork {
late final DioAdapter _dioAdapter = DioAdapter(dio: dio);

DioAdapter get dioAdapter => _dioAdapter;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/network/network.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export 'api.dart';
export 'dio_network.dart';
export 'mock_api.dart';
export 'api_response.dart';
export 'dto/dto.dart';
4 changes: 4 additions & 0 deletions lib/core/utils/bloc/base_bloc_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ abstract class BaseBlocStatus {

factory BaseBlocStatus.failure() => BaseBlocStatusFailure();

bool get isInitial => this is BaseBlocStatusInitial;

bool get isLoading => this is BaseBlocStatusLoading;

bool get isSuccess => this is BaseBlocStatusSuccess;

bool get isFailure => this is BaseBlocStatusFailure;

bool get isRefresh => this is BaseBlocStatusRefresh;
}

Expand Down
13 changes: 13 additions & 0 deletions lib/core/utils/injections.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import 'package:get_it/get_it.dart';
import 'package:withu_app/core/core.dart';
import 'package:withu_app/feature/account/account.dart';
import 'package:withu_app/feature/job_posting/init_injections.dart';
import 'package:withu_app/feature/splash/splash.dart';

final getIt = GetIt.instance;

AppRouter get getItAppRouter => getIt<AppRouter>();

void initCommonInjections() {
getIt.registerSingleton<DioNetwork>(DioNetwork());
}

void initRouterInjections() {
getIt.registerSingleton<AppRouter>(AppRouter());
}

Future<void> initInjections() async {
initRouterInjections();
initCommonInjections();
initAccountInjections();
initSplashInjections();
initJobPostingInjections();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ part 'login_request_dto.freezed.dart';

part 'login_request_dto.g.dart';

part 'login_request_dto.mock.dart';

@freezed
class LoginRequestDto with _$LoginRequestDto {
factory LoginRequestDto({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
part of 'login_request_dto.dart';

extension LoginRequestDtoMock on LoginRequestDto {
static LoginRequestDto mock() {
return LoginRequestDto(
accountType: AccountType.company,
loginType: LoginType.email,
loginId: '[email protected]',
password: '123qwe!@',
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension LoginResponseDtoMock on LoginResponseDto {
);
}

static LoginResponseDto fail() {
static LoginResponseDto failure() {
return LoginResponseDto(
status: false,
message: "존재하지 않는 계정입니다.",
Expand Down
12 changes: 9 additions & 3 deletions lib/feature/account/data/data_sources/mock/mock_api.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import 'dart:async';

import 'package:http_mock_adapter/http_mock_adapter.dart';
import 'package:withu_app/core/core.dart';
import 'package:withu_app/feature/account/account.dart';

class AccountMockApi extends AccountApiImpl with MockAPI {
class AccountMockApi extends AccountApiImpl {
late final DioAdapter dioAdapter;

AccountMockApi({required super.network}) {
dioAdapter = DioAdapter(dio: network.dio);
}

/// 로그인 API
@override
FutureOr<ApiResponse<LoginResponseDto>> login({
Expand All @@ -14,7 +20,7 @@ class AccountMockApi extends AccountApiImpl with MockAPI {
loginPath,
(server) => server.reply(
200,
LoginResponseDtoMock.success().toJson(),
LoginResponseDtoMock.failure().toJson(),
delay: const Duration(seconds: 1),
),
data: requestData.toJson(),
Expand Down
3 changes: 1 addition & 2 deletions lib/feature/account/data/data_sources/remote/api.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'dart:async';

import 'package:withu_app/core/core.dart';
import 'package:withu_app/feature/account/data/data_sources/dto/dto.dart';

abstract class AccountApi extends API {
abstract class AccountApi {
/// API 주소
final path = "/api/account";

Expand Down
12 changes: 9 additions & 3 deletions lib/feature/account/data/data_sources/remote/api_impl.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import 'dart:async';
import 'package:withu_app/core/network/api_response.dart';
import 'package:withu_app/core/core.dart';
import 'package:withu_app/feature/account/data/data_sources/dto/dto.dart';
import 'api.dart';

class AccountApiImpl extends AccountApi {
final DioNetwork network;

AccountApiImpl({required this.network});

/// 로그인 API
@override
FutureOr<ApiResponse<LoginResponseDto>> login({
required LoginRequestDto requestData,
}) async {
return dio
return network.dio
.post(
loginPath,
data: requestData.toJson(),
)
.then((response) => ApiResponse.success(
LoginResponseDto.fromJson(response.data),
))
.catchError((_) => const ApiResponse<LoginResponseDto>.error());
.catchError(
(_) => ApiResponse<LoginResponseDto>.fail(FailResponse.error()),
);
}
}
2 changes: 1 addition & 1 deletion lib/feature/account/domain/domain.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export 'usecase/usecase.dart';
export 'repository//repository.dart';
export 'repository/repository.dart';
export 'entity/entity.dart';
2 changes: 1 addition & 1 deletion lib/feature/account/domain/entity/entity.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export 'login/login_result_entity.dart';
export 'login/login.dart';
2 changes: 2 additions & 0 deletions lib/feature/account/domain/entity/login/login.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'request/login_request_entity.dart';
export 'result/login_result_entity.dart';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
part of 'login_request_entity.dart';

extension LoginRequestEntityConverter on LoginRequestEntity {
/// entity -> dto
LoginRequestDto toDto() {
return LoginRequestDto(
accountType: accountType,
loginType: loginType,
loginId: loginId,
password: password,
);
}
}
Loading

0 comments on commit c8896ae

Please sign in to comment.