refactor: Clean Architecture 적용 및 코드베이스 전면 리팩토링
## 주요 변경사항 ### 아키텍처 개선 - Clean Architecture 패턴 적용 (Domain, Data, Presentation 레이어 분리) - Use Case 패턴 도입으로 비즈니스 로직 캡슐화 - Repository 패턴으로 데이터 접근 추상화 - 의존성 주입 구조 개선 ### 상태 관리 최적화 - 모든 Controller에서 불필요한 상태 관리 로직 제거 - 페이지네이션 로직 통일 및 간소화 - 에러 처리 로직 개선 (에러 메시지 한글화) - 로딩 상태 관리 최적화 ### Mock 서비스 제거 - MockDataService 완전 제거 - 모든 화면을 실제 API 전용으로 전환 - 불필요한 Mock 관련 코드 정리 ### UI/UX 개선 - Overview 화면 대시보드 기능 강화 - 라이선스 만료 알림 위젯 추가 - 사이드바 네비게이션 개선 - 일관된 UI 컴포넌트 사용 ### 코드 품질 - 중복 코드 제거 및 함수 추출 - 파일별 책임 분리 명확화 - 테스트 코드 업데이트 ## 영향 범위 - 모든 화면의 Controller 리팩토링 - API 통신 레이어 구조 개선 - 에러 처리 및 로깅 시스템 개선 ## 향후 계획 - 단위 테스트 커버리지 확대 - 통합 테스트 시나리오 추가 - 성능 모니터링 도구 통합
This commit is contained in:
231
test/domain/usecases/auth/login_usecase_test.dart
Normal file
231
test/domain/usecases/auth/login_usecase_test.dart
Normal file
@@ -0,0 +1,231 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:superport/domain/usecases/auth/login_usecase.dart';
|
||||
import 'package:superport/domain/usecases/base_usecase.dart';
|
||||
import 'package:superport/services/auth_service.dart';
|
||||
import 'package:superport/data/models/auth/login_request.dart';
|
||||
import 'package:superport/data/models/auth/login_response.dart';
|
||||
import 'package:superport/data/models/auth/auth_user.dart';
|
||||
import 'package:superport/core/utils/error_handler.dart';
|
||||
|
||||
import 'login_usecase_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([AuthService])
|
||||
void main() {
|
||||
late LoginUseCase loginUseCase;
|
||||
late MockAuthService mockAuthService;
|
||||
|
||||
setUp(() {
|
||||
mockAuthService = MockAuthService();
|
||||
loginUseCase = LoginUseCase(mockAuthService);
|
||||
});
|
||||
|
||||
group('LoginUseCase', () {
|
||||
const tEmail = 'test@example.com';
|
||||
const tPassword = 'password123!';
|
||||
const tInvalidEmail = 'invalid-email';
|
||||
const tEmptyPassword = '';
|
||||
|
||||
final tLoginRequest = LoginRequest(
|
||||
email: tEmail,
|
||||
password: tPassword,
|
||||
);
|
||||
|
||||
final tLoginResponse = LoginResponse(
|
||||
accessToken: 'test_access_token',
|
||||
refreshToken: 'test_refresh_token',
|
||||
tokenType: 'Bearer',
|
||||
expiresIn: 3600,
|
||||
user: AuthUser(
|
||||
id: 1,
|
||||
username: 'testuser',
|
||||
email: tEmail,
|
||||
name: 'Test User',
|
||||
role: 'U',
|
||||
),
|
||||
);
|
||||
|
||||
test('로그인 성공 시 Right(LoginResponse) 반환', () async {
|
||||
// arrange
|
||||
when(mockAuthService.login(any))
|
||||
.thenAnswer((_) async => tLoginResponse);
|
||||
|
||||
// act
|
||||
final result = await loginUseCase(
|
||||
LoginParams(email: tEmail, password: tPassword),
|
||||
);
|
||||
|
||||
// assert
|
||||
expect(result, Right(tLoginResponse));
|
||||
verify(mockAuthService.login(argThat(
|
||||
predicate<LoginRequest>((req) =>
|
||||
req.email == tEmail && req.password == tPassword),
|
||||
))).called(1);
|
||||
verifyNoMoreInteractions(mockAuthService);
|
||||
});
|
||||
|
||||
test('잘못된 이메일 형식 입력 시 ValidationFailure 반환', () async {
|
||||
// act
|
||||
final result = await loginUseCase(
|
||||
LoginParams(email: tInvalidEmail, password: tPassword),
|
||||
);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<AppFailure>());
|
||||
expect(failure.message, '올바른 이메일 형식이 아닙니다.');
|
||||
},
|
||||
(_) => fail('Should return failure'),
|
||||
);
|
||||
verifyNever(mockAuthService.login(any));
|
||||
});
|
||||
|
||||
test('빈 비밀번호 입력 시 ValidationFailure 반환', () async {
|
||||
// act
|
||||
final result = await loginUseCase(
|
||||
LoginParams(email: tEmail, password: tEmptyPassword),
|
||||
);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<AppFailure>());
|
||||
expect(failure.message, '비밀번호를 입력해주세요.');
|
||||
},
|
||||
(_) => fail('Should return failure'),
|
||||
);
|
||||
verifyNever(mockAuthService.login(any));
|
||||
});
|
||||
|
||||
test('401 에러 시 AuthFailure 반환', () async {
|
||||
// arrange
|
||||
final dioError = DioException(
|
||||
requestOptions: RequestOptions(path: '/login'),
|
||||
response: Response(
|
||||
requestOptions: RequestOptions(path: '/login'),
|
||||
statusCode: 401,
|
||||
),
|
||||
type: DioExceptionType.badResponse,
|
||||
);
|
||||
|
||||
when(mockAuthService.login(any)).thenThrow(dioError);
|
||||
|
||||
// act
|
||||
final result = await loginUseCase(
|
||||
LoginParams(email: tEmail, password: tPassword),
|
||||
);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<AppFailure>());
|
||||
expect(failure.message, contains('인증'));
|
||||
},
|
||||
(_) => fail('Should return failure'),
|
||||
);
|
||||
});
|
||||
|
||||
test('네트워크 타임아웃 시 NetworkFailure 반환', () async {
|
||||
// arrange
|
||||
final dioError = DioException(
|
||||
requestOptions: RequestOptions(path: '/login'),
|
||||
type: DioExceptionType.connectionTimeout,
|
||||
);
|
||||
|
||||
when(mockAuthService.login(any)).thenThrow(dioError);
|
||||
|
||||
// act
|
||||
final result = await loginUseCase(
|
||||
LoginParams(email: tEmail, password: tPassword),
|
||||
);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<AppFailure>());
|
||||
expect(failure.message, contains('네트워크'));
|
||||
},
|
||||
(_) => fail('Should return failure'),
|
||||
);
|
||||
});
|
||||
|
||||
test('서버 에러 시 ServerFailure 반환', () async {
|
||||
// arrange
|
||||
final dioError = DioException(
|
||||
requestOptions: RequestOptions(path: '/login'),
|
||||
response: Response(
|
||||
requestOptions: RequestOptions(path: '/login'),
|
||||
statusCode: 500,
|
||||
data: {'message': '서버 내부 오류'},
|
||||
),
|
||||
type: DioExceptionType.badResponse,
|
||||
);
|
||||
|
||||
when(mockAuthService.login(any)).thenThrow(dioError);
|
||||
|
||||
// act
|
||||
final result = await loginUseCase(
|
||||
LoginParams(email: tEmail, password: tPassword),
|
||||
);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<AppFailure>());
|
||||
expect(failure.message, contains('서버'));
|
||||
},
|
||||
(_) => fail('Should return failure'),
|
||||
);
|
||||
});
|
||||
|
||||
test('예상치 못한 에러 시 UnknownFailure 반환', () async {
|
||||
// arrange
|
||||
when(mockAuthService.login(any))
|
||||
.thenThrow(Exception('Unexpected error'));
|
||||
|
||||
// act
|
||||
final result = await loginUseCase(
|
||||
LoginParams(email: tEmail, password: tPassword),
|
||||
);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<AppFailure>());
|
||||
expect(failure.message, contains('오류'));
|
||||
},
|
||||
(_) => fail('Should return failure'),
|
||||
);
|
||||
});
|
||||
|
||||
test('로그인 실패 시 (null 반환) AuthFailure 반환', () async {
|
||||
// arrange
|
||||
when(mockAuthService.login(any)).thenAnswer((_) async => null);
|
||||
|
||||
// act
|
||||
final result = await loginUseCase(
|
||||
LoginParams(email: tEmail, password: tPassword),
|
||||
);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<AppFailure>());
|
||||
expect(failure.message, contains('로그인'));
|
||||
},
|
||||
(_) => fail('Should return failure'),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
153
test/domain/usecases/auth/login_usecase_test.mocks.dart
Normal file
153
test/domain/usecases/auth/login_usecase_test.mocks.dart
Normal file
@@ -0,0 +1,153 @@
|
||||
// Mocks generated by Mockito 5.4.5 from annotations
|
||||
// in superport/test/domain/usecases/auth/login_usecase_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
import 'package:dartz/dartz.dart' as _i2;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:superport/core/errors/failures.dart' as _i5;
|
||||
import 'package:superport/data/models/auth/auth_user.dart' as _i9;
|
||||
import 'package:superport/data/models/auth/login_request.dart' as _i7;
|
||||
import 'package:superport/data/models/auth/login_response.dart' as _i6;
|
||||
import 'package:superport/data/models/auth/token_response.dart' as _i8;
|
||||
import 'package:superport/services/auth_service.dart' as _i3;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
// ignore_for_file: avoid_setters_without_getters
|
||||
// ignore_for_file: comment_references
|
||||
// ignore_for_file: deprecated_member_use
|
||||
// ignore_for_file: deprecated_member_use_from_same_package
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: invalid_use_of_visible_for_testing_member
|
||||
// ignore_for_file: must_be_immutable
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
// ignore_for_file: unnecessary_parenthesis
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: subtype_of_sealed_class
|
||||
|
||||
class _FakeEither_0<L, R> extends _i1.SmartFake implements _i2.Either<L, R> {
|
||||
_FakeEither_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [AuthService].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockAuthService extends _i1.Mock implements _i3.AuthService {
|
||||
MockAuthService() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Stream<bool> get authStateChanges => (super.noSuchMethod(
|
||||
Invocation.getter(#authStateChanges),
|
||||
returnValue: _i4.Stream<bool>.empty(),
|
||||
) as _i4.Stream<bool>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.Either<_i5.Failure, _i6.LoginResponse>> login(
|
||||
_i7.LoginRequest? request) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#login,
|
||||
[request],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.Either<_i5.Failure, _i6.LoginResponse>>.value(
|
||||
_FakeEither_0<_i5.Failure, _i6.LoginResponse>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#login,
|
||||
[request],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.Either<_i5.Failure, _i6.LoginResponse>>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.Either<_i5.Failure, void>> logout() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#logout,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.Either<_i5.Failure, void>>.value(
|
||||
_FakeEither_0<_i5.Failure, void>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#logout,
|
||||
[],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.Either<_i5.Failure, void>>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.Either<_i5.Failure, _i8.TokenResponse>> refreshToken() =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#refreshToken,
|
||||
[],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.Either<_i5.Failure, _i8.TokenResponse>>.value(
|
||||
_FakeEither_0<_i5.Failure, _i8.TokenResponse>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#refreshToken,
|
||||
[],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.Either<_i5.Failure, _i8.TokenResponse>>);
|
||||
|
||||
@override
|
||||
_i4.Future<bool> isLoggedIn() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#isLoggedIn,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<bool>.value(false),
|
||||
) as _i4.Future<bool>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i9.AuthUser?> getCurrentUser() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getCurrentUser,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<_i9.AuthUser?>.value(),
|
||||
) as _i4.Future<_i9.AuthUser?>);
|
||||
|
||||
@override
|
||||
_i4.Future<String?> getAccessToken() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getAccessToken,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<String?>.value(),
|
||||
) as _i4.Future<String?>);
|
||||
|
||||
@override
|
||||
_i4.Future<String?> getRefreshToken() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getRefreshToken,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<String?>.value(),
|
||||
) as _i4.Future<String?>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> clearSession() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#clearSession,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
}
|
||||
189
test/domain/usecases/license/create_license_usecase_test.dart
Normal file
189
test/domain/usecases/license/create_license_usecase_test.dart
Normal file
@@ -0,0 +1,189 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:superport/data/models/license/license_dto.dart';
|
||||
import 'package:superport/data/repositories/license_repository.dart';
|
||||
import 'package:superport/domain/usecases/base_usecase.dart';
|
||||
import 'package:superport/domain/usecases/license/create_license_usecase.dart';
|
||||
|
||||
import 'create_license_usecase_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([LicenseRepository])
|
||||
void main() {
|
||||
late CreateLicenseUseCase useCase;
|
||||
late MockLicenseRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockLicenseRepository();
|
||||
useCase = CreateLicenseUseCase(mockRepository);
|
||||
});
|
||||
|
||||
group('CreateLicenseUseCase', () {
|
||||
final validParams = CreateLicenseParams(
|
||||
equipmentId: 1,
|
||||
companyId: 1,
|
||||
licenseType: 'maintenance',
|
||||
startDate: DateTime(2025, 1, 1),
|
||||
expiryDate: DateTime(2025, 12, 31),
|
||||
description: 'Test license',
|
||||
cost: 1000.0,
|
||||
);
|
||||
|
||||
final mockLicense = LicenseDto(
|
||||
id: 1,
|
||||
equipmentId: 1,
|
||||
companyId: 1,
|
||||
licenseType: 'maintenance',
|
||||
startDate: DateTime(2025, 1, 1),
|
||||
expiryDate: DateTime(2025, 12, 31),
|
||||
description: 'Test license',
|
||||
cost: 1000.0,
|
||||
status: 'active',
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
|
||||
test('라이선스 생성 성공', () async {
|
||||
// arrange
|
||||
when(mockRepository.createLicense(any))
|
||||
.thenAnswer((_) async => mockLicense);
|
||||
|
||||
// act
|
||||
final result = await useCase(validParams);
|
||||
|
||||
// assert
|
||||
expect(result.isRight(), true);
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(license) => expect(license, equals(mockLicense)),
|
||||
);
|
||||
verify(mockRepository.createLicense(validParams.toMap())).called(1);
|
||||
});
|
||||
|
||||
test('만료일이 시작일보다 이전인 경우 검증 실패', () async {
|
||||
// arrange
|
||||
final invalidParams = CreateLicenseParams(
|
||||
equipmentId: 1,
|
||||
companyId: 1,
|
||||
licenseType: 'maintenance',
|
||||
startDate: DateTime(2025, 12, 31),
|
||||
expiryDate: DateTime(2025, 1, 1), // 시작일보다 이전
|
||||
description: 'Test license',
|
||||
cost: 1000.0,
|
||||
);
|
||||
|
||||
// act
|
||||
final result = await useCase(invalidParams);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<ValidationFailure>());
|
||||
expect(failure.message, contains('만료일은 시작일 이후여야 합니다'));
|
||||
},
|
||||
(license) => fail('Should not return license'),
|
||||
);
|
||||
verifyNever(mockRepository.createLicense(any));
|
||||
});
|
||||
|
||||
test('라이선스 기간이 30일 미만인 경우 검증 실패', () async {
|
||||
// arrange
|
||||
final invalidParams = CreateLicenseParams(
|
||||
equipmentId: 1,
|
||||
companyId: 1,
|
||||
licenseType: 'maintenance',
|
||||
startDate: DateTime(2025, 1, 1),
|
||||
expiryDate: DateTime(2025, 1, 15), // 15일 기간
|
||||
description: 'Test license',
|
||||
cost: 1000.0,
|
||||
);
|
||||
|
||||
// act
|
||||
final result = await useCase(invalidParams);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<ValidationFailure>());
|
||||
expect(failure.message, contains('라이선스 기간은 최소 30일 이상이어야 합니다'));
|
||||
},
|
||||
(license) => fail('Should not return license'),
|
||||
);
|
||||
verifyNever(mockRepository.createLicense(any));
|
||||
});
|
||||
|
||||
test('Repository에서 예외 발생 시 ServerFailure 반환', () async {
|
||||
// arrange
|
||||
when(mockRepository.createLicense(any))
|
||||
.thenThrow(Exception('Server error'));
|
||||
|
||||
// act
|
||||
final result = await useCase(validParams);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<ServerFailure>());
|
||||
expect(failure.message, contains('Server error'));
|
||||
},
|
||||
(license) => fail('Should not return license'),
|
||||
);
|
||||
verify(mockRepository.createLicense(validParams.toMap())).called(1);
|
||||
});
|
||||
|
||||
test('파라미터를 올바른 Map으로 변환', () {
|
||||
// arrange
|
||||
final params = CreateLicenseParams(
|
||||
equipmentId: 1,
|
||||
companyId: 2,
|
||||
licenseType: 'maintenance',
|
||||
startDate: DateTime(2025, 1, 1),
|
||||
expiryDate: DateTime(2025, 12, 31),
|
||||
description: 'Test description',
|
||||
cost: 5000.0,
|
||||
);
|
||||
|
||||
// act
|
||||
final map = params.toMap();
|
||||
|
||||
// assert
|
||||
expect(map['equipment_id'], equals(1));
|
||||
expect(map['company_id'], equals(2));
|
||||
expect(map['license_type'], equals('maintenance'));
|
||||
expect(map['start_date'], equals(DateTime(2025, 1, 1).toIso8601String()));
|
||||
expect(map['expiry_date'], equals(DateTime(2025, 12, 31).toIso8601String()));
|
||||
expect(map['description'], equals('Test description'));
|
||||
expect(map['cost'], equals(5000.0));
|
||||
});
|
||||
|
||||
test('옵셔널 파라미터가 null인 경우에도 정상 처리', () async {
|
||||
// arrange
|
||||
final paramsWithNulls = CreateLicenseParams(
|
||||
equipmentId: 1,
|
||||
companyId: 1,
|
||||
licenseType: 'maintenance',
|
||||
startDate: DateTime(2025, 1, 1),
|
||||
expiryDate: DateTime(2025, 12, 31),
|
||||
description: null,
|
||||
cost: null,
|
||||
);
|
||||
|
||||
when(mockRepository.createLicense(any))
|
||||
.thenAnswer((_) async => mockLicense);
|
||||
|
||||
// act
|
||||
final result = await useCase(paramsWithNulls);
|
||||
|
||||
// assert
|
||||
expect(result.isRight(), true);
|
||||
|
||||
final map = paramsWithNulls.toMap();
|
||||
expect(map['description'], isNull);
|
||||
expect(map['cost'], isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
// Mocks generated by Mockito 5.4.5 from annotations
|
||||
// in superport/test/domain/usecases/license/create_license_usecase_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:superport/data/models/license/license_dto.dart' as _i2;
|
||||
import 'package:superport/data/repositories/license_repository.dart' as _i3;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
// ignore_for_file: avoid_setters_without_getters
|
||||
// ignore_for_file: comment_references
|
||||
// ignore_for_file: deprecated_member_use
|
||||
// ignore_for_file: deprecated_member_use_from_same_package
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: invalid_use_of_visible_for_testing_member
|
||||
// ignore_for_file: must_be_immutable
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
// ignore_for_file: unnecessary_parenthesis
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: subtype_of_sealed_class
|
||||
|
||||
class _FakeLicenseListResponseDto_0 extends _i1.SmartFake
|
||||
implements _i2.LicenseListResponseDto {
|
||||
_FakeLicenseListResponseDto_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeLicenseDto_1 extends _i1.SmartFake implements _i2.LicenseDto {
|
||||
_FakeLicenseDto_1(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [LicenseRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockLicenseRepository extends _i1.Mock implements _i3.LicenseRepository {
|
||||
MockLicenseRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.LicenseListResponseDto> getLicenses({
|
||||
int? page = 1,
|
||||
int? perPage = 20,
|
||||
String? search,
|
||||
Map<String, dynamic>? filters,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getLicenses,
|
||||
[],
|
||||
{
|
||||
#page: page,
|
||||
#perPage: perPage,
|
||||
#search: search,
|
||||
#filters: filters,
|
||||
},
|
||||
),
|
||||
returnValue: _i4.Future<_i2.LicenseListResponseDto>.value(
|
||||
_FakeLicenseListResponseDto_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getLicenses,
|
||||
[],
|
||||
{
|
||||
#page: page,
|
||||
#perPage: perPage,
|
||||
#search: search,
|
||||
#filters: filters,
|
||||
},
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.LicenseListResponseDto>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.LicenseDto> getLicenseDetail(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getLicenseDetail,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.LicenseDto>.value(_FakeLicenseDto_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getLicenseDetail,
|
||||
[id],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.LicenseDto>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.LicenseDto> createLicense(Map<String, dynamic>? data) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#createLicense,
|
||||
[data],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.LicenseDto>.value(_FakeLicenseDto_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#createLicense,
|
||||
[data],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.LicenseDto>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.LicenseDto> updateLicense(
|
||||
int? id,
|
||||
Map<String, dynamic>? data,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateLicense,
|
||||
[
|
||||
id,
|
||||
data,
|
||||
],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.LicenseDto>.value(_FakeLicenseDto_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateLicense,
|
||||
[
|
||||
id,
|
||||
data,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.LicenseDto>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> deleteLicense(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteLicense,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:superport/data/models/warehouse_location/warehouse_location.dart';
|
||||
import 'package:superport/data/repositories/warehouse_location_repository.dart';
|
||||
import 'package:superport/domain/usecases/base_usecase.dart';
|
||||
import 'package:superport/domain/usecases/warehouse_location/create_warehouse_location_usecase.dart';
|
||||
|
||||
import 'create_warehouse_location_usecase_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([WarehouseLocationRepository])
|
||||
void main() {
|
||||
late CreateWarehouseLocationUseCase useCase;
|
||||
late MockWarehouseLocationRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockWarehouseLocationRepository();
|
||||
useCase = CreateWarehouseLocationUseCase(mockRepository);
|
||||
});
|
||||
|
||||
group('CreateWarehouseLocationUseCase', () {
|
||||
final validParams = CreateWarehouseLocationParams(
|
||||
name: 'Main Warehouse',
|
||||
address: '123 Storage Street',
|
||||
description: 'Primary storage location',
|
||||
contactNumber: '010-1234-5678',
|
||||
manager: 'John Doe',
|
||||
latitude: 37.5665,
|
||||
longitude: 126.9780,
|
||||
);
|
||||
|
||||
final mockLocation = WarehouseLocation(
|
||||
id: 1,
|
||||
name: 'Main Warehouse',
|
||||
address: '123 Storage Street',
|
||||
description: 'Primary storage location',
|
||||
contactNumber: '010-1234-5678',
|
||||
manager: 'John Doe',
|
||||
latitude: 37.5665,
|
||||
longitude: 126.9780,
|
||||
isActive: true,
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
|
||||
test('창고 위치 생성 성공', () async {
|
||||
// arrange
|
||||
when(mockRepository.createWarehouseLocation(any))
|
||||
.thenAnswer((_) async => mockLocation);
|
||||
|
||||
// act
|
||||
final result = await useCase(validParams);
|
||||
|
||||
// assert
|
||||
expect(result.isRight(), true);
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(location) => expect(location, equals(mockLocation)),
|
||||
);
|
||||
verify(mockRepository.createWarehouseLocation(validParams.toMap())).called(1);
|
||||
});
|
||||
|
||||
test('창고 이름이 비어있는 경우 검증 실패', () async {
|
||||
// arrange
|
||||
final invalidParams = CreateWarehouseLocationParams(
|
||||
name: '', // 빈 이름
|
||||
address: '123 Storage Street',
|
||||
);
|
||||
|
||||
// act
|
||||
final result = await useCase(invalidParams);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<ValidationFailure>());
|
||||
expect(failure.message, contains('창고 위치 이름은 필수입니다'));
|
||||
},
|
||||
(location) => fail('Should not return location'),
|
||||
);
|
||||
verifyNever(mockRepository.createWarehouseLocation(any));
|
||||
});
|
||||
|
||||
test('창고 주소가 비어있는 경우 검증 실패', () async {
|
||||
// arrange
|
||||
final invalidParams = CreateWarehouseLocationParams(
|
||||
name: 'Main Warehouse',
|
||||
address: '', // 빈 주소
|
||||
);
|
||||
|
||||
// act
|
||||
final result = await useCase(invalidParams);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<ValidationFailure>());
|
||||
expect(failure.message, contains('창고 주소는 필수입니다'));
|
||||
},
|
||||
(location) => fail('Should not return location'),
|
||||
);
|
||||
verifyNever(mockRepository.createWarehouseLocation(any));
|
||||
});
|
||||
|
||||
test('잘못된 연락처 형식인 경우 검증 실패', () async {
|
||||
// arrange
|
||||
final invalidParams = CreateWarehouseLocationParams(
|
||||
name: 'Main Warehouse',
|
||||
address: '123 Storage Street',
|
||||
contactNumber: 'invalid-phone!@#', // 잘못된 형식
|
||||
);
|
||||
|
||||
// act
|
||||
final result = await useCase(invalidParams);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<ValidationFailure>());
|
||||
expect(failure.message, contains('올바른 연락처 형식이 아닙니다'));
|
||||
},
|
||||
(location) => fail('Should not return location'),
|
||||
);
|
||||
verifyNever(mockRepository.createWarehouseLocation(any));
|
||||
});
|
||||
|
||||
test('올바른 연락처 형식들 허용', () async {
|
||||
// arrange
|
||||
final validPhoneNumbers = [
|
||||
'010-1234-5678',
|
||||
'02-123-4567',
|
||||
'+82-10-1234-5678',
|
||||
'(02) 123-4567',
|
||||
'010 1234 5678',
|
||||
];
|
||||
|
||||
when(mockRepository.createWarehouseLocation(any))
|
||||
.thenAnswer((_) async => mockLocation);
|
||||
|
||||
// act & assert
|
||||
for (final phone in validPhoneNumbers) {
|
||||
final params = CreateWarehouseLocationParams(
|
||||
name: 'Main Warehouse',
|
||||
address: '123 Storage Street',
|
||||
contactNumber: phone,
|
||||
);
|
||||
|
||||
final result = await useCase(params);
|
||||
expect(result.isRight(), true);
|
||||
}
|
||||
});
|
||||
|
||||
test('Repository에서 예외 발생 시 ServerFailure 반환', () async {
|
||||
// arrange
|
||||
when(mockRepository.createWarehouseLocation(any))
|
||||
.thenThrow(Exception('Server error'));
|
||||
|
||||
// act
|
||||
final result = await useCase(validParams);
|
||||
|
||||
// assert
|
||||
expect(result.isLeft(), true);
|
||||
result.fold(
|
||||
(failure) {
|
||||
expect(failure, isA<ServerFailure>());
|
||||
expect(failure.message, contains('Server error'));
|
||||
},
|
||||
(location) => fail('Should not return location'),
|
||||
);
|
||||
verify(mockRepository.createWarehouseLocation(validParams.toMap())).called(1);
|
||||
});
|
||||
|
||||
test('파라미터를 올바른 Map으로 변환', () {
|
||||
// arrange
|
||||
final params = CreateWarehouseLocationParams(
|
||||
name: 'Test Warehouse',
|
||||
address: '456 Test Avenue',
|
||||
description: 'Test description',
|
||||
contactNumber: '010-9876-5432',
|
||||
manager: 'Jane Smith',
|
||||
latitude: 35.1796,
|
||||
longitude: 129.0756,
|
||||
);
|
||||
|
||||
// act
|
||||
final map = params.toMap();
|
||||
|
||||
// assert
|
||||
expect(map['name'], equals('Test Warehouse'));
|
||||
expect(map['address'], equals('456 Test Avenue'));
|
||||
expect(map['description'], equals('Test description'));
|
||||
expect(map['contact_number'], equals('010-9876-5432'));
|
||||
expect(map['manager'], equals('Jane Smith'));
|
||||
expect(map['latitude'], equals(35.1796));
|
||||
expect(map['longitude'], equals(129.0756));
|
||||
});
|
||||
|
||||
test('옵셔널 파라미터가 null인 경우에도 정상 처리', () async {
|
||||
// arrange
|
||||
final paramsWithNulls = CreateWarehouseLocationParams(
|
||||
name: 'Main Warehouse',
|
||||
address: '123 Storage Street',
|
||||
description: null,
|
||||
contactNumber: null,
|
||||
manager: null,
|
||||
latitude: null,
|
||||
longitude: null,
|
||||
);
|
||||
|
||||
when(mockRepository.createWarehouseLocation(any))
|
||||
.thenAnswer((_) async => mockLocation);
|
||||
|
||||
// act
|
||||
final result = await useCase(paramsWithNulls);
|
||||
|
||||
// assert
|
||||
expect(result.isRight(), true);
|
||||
|
||||
final map = paramsWithNulls.toMap();
|
||||
expect(map['description'], isNull);
|
||||
expect(map['contact_number'], isNull);
|
||||
expect(map['manager'], isNull);
|
||||
expect(map['latitude'], isNull);
|
||||
expect(map['longitude'], isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
// Mocks generated by Mockito 5.4.5 from annotations
|
||||
// in superport/test/domain/usecases/warehouse_location/create_warehouse_location_usecase_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:superport/data/models/warehouse/warehouse_dto.dart' as _i2;
|
||||
import 'package:superport/data/repositories/warehouse_location_repository.dart'
|
||||
as _i3;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
// ignore_for_file: avoid_setters_without_getters
|
||||
// ignore_for_file: comment_references
|
||||
// ignore_for_file: deprecated_member_use
|
||||
// ignore_for_file: deprecated_member_use_from_same_package
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: invalid_use_of_visible_for_testing_member
|
||||
// ignore_for_file: must_be_immutable
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
// ignore_for_file: unnecessary_parenthesis
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: subtype_of_sealed_class
|
||||
|
||||
class _FakeWarehouseLocationListDto_0 extends _i1.SmartFake
|
||||
implements _i2.WarehouseLocationListDto {
|
||||
_FakeWarehouseLocationListDto_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
class _FakeWarehouseLocationDto_1 extends _i1.SmartFake
|
||||
implements _i2.WarehouseLocationDto {
|
||||
_FakeWarehouseLocationDto_1(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [WarehouseLocationRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockWarehouseLocationRepository extends _i1.Mock
|
||||
implements _i3.WarehouseLocationRepository {
|
||||
MockWarehouseLocationRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.WarehouseLocationListDto> getWarehouseLocations({
|
||||
int? page = 1,
|
||||
int? perPage = 20,
|
||||
String? search,
|
||||
Map<String, dynamic>? filters,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getWarehouseLocations,
|
||||
[],
|
||||
{
|
||||
#page: page,
|
||||
#perPage: perPage,
|
||||
#search: search,
|
||||
#filters: filters,
|
||||
},
|
||||
),
|
||||
returnValue: _i4.Future<_i2.WarehouseLocationListDto>.value(
|
||||
_FakeWarehouseLocationListDto_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getWarehouseLocations,
|
||||
[],
|
||||
{
|
||||
#page: page,
|
||||
#perPage: perPage,
|
||||
#search: search,
|
||||
#filters: filters,
|
||||
},
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.WarehouseLocationListDto>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.WarehouseLocationDto> getWarehouseLocationDetail(int? id) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getWarehouseLocationDetail,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.WarehouseLocationDto>.value(
|
||||
_FakeWarehouseLocationDto_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getWarehouseLocationDetail,
|
||||
[id],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.WarehouseLocationDto>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.WarehouseLocationDto> createWarehouseLocation(
|
||||
Map<String, dynamic>? data) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#createWarehouseLocation,
|
||||
[data],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.WarehouseLocationDto>.value(
|
||||
_FakeWarehouseLocationDto_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#createWarehouseLocation,
|
||||
[data],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.WarehouseLocationDto>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.WarehouseLocationDto> updateWarehouseLocation(
|
||||
int? id,
|
||||
Map<String, dynamic>? data,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateWarehouseLocation,
|
||||
[
|
||||
id,
|
||||
data,
|
||||
],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.WarehouseLocationDto>.value(
|
||||
_FakeWarehouseLocationDto_1(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateWarehouseLocation,
|
||||
[
|
||||
id,
|
||||
data,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.WarehouseLocationDto>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> deleteWarehouseLocation(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteWarehouseLocation,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
|
||||
@override
|
||||
_i4.Future<bool> checkWarehouseHasEquipment(int? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#checkWarehouseHasEquipment,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i4.Future<bool>.value(false),
|
||||
) as _i4.Future<bool>);
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import 'package:superport/data/models/auth/login_request.dart';
|
||||
import 'package:superport/data/models/equipment/equipment_out_request.dart';
|
||||
import 'package:superport/models/equipment_unified_model.dart';
|
||||
import 'package:superport/screens/equipment/controllers/equipment_list_controller.dart';
|
||||
import 'package:superport/services/mock_data_service.dart';
|
||||
// MockDataService는 제거됨
|
||||
import '../real_api/test_helper.dart';
|
||||
|
||||
/// 체크박스 → 장비출고 인터랙티브 기능 테스트
|
||||
@@ -43,10 +43,8 @@ class CheckboxEquipmentOutTest {
|
||||
companyService = getIt<CompanyService>();
|
||||
authService = getIt<AuthService>();
|
||||
|
||||
// Controller 초기화
|
||||
controller = EquipmentListController(
|
||||
dataService: MockDataService(),
|
||||
);
|
||||
// Controller 초기화 (MockDataService 제거됨)
|
||||
controller = EquipmentListController();
|
||||
|
||||
// 인증
|
||||
await _ensureAuthenticated();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:superport/data/datasources/remote/api_client.dart';
|
||||
import 'package:superport/services/auth_service.dart';
|
||||
@@ -9,7 +8,6 @@ import 'package:superport/models/license_model.dart';
|
||||
import 'package:superport/models/company_model.dart';
|
||||
import 'package:superport/models/address_model.dart';
|
||||
import 'package:superport/data/models/auth/login_request.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'dart:math';
|
||||
import 'real_api/test_helper.dart';
|
||||
|
||||
@@ -18,7 +16,6 @@ void main() {
|
||||
late AuthService authService;
|
||||
late LicenseService licenseService;
|
||||
late CompanyService companyService;
|
||||
late ApiClient apiClient;
|
||||
|
||||
setUpAll(() async {
|
||||
// RealApiTestHelper를 사용하여 Mock Storage와 함께 테스트 환경 설정
|
||||
@@ -28,7 +25,6 @@ void main() {
|
||||
getIt = GetIt.instance;
|
||||
|
||||
// 서비스 초기화
|
||||
apiClient = getIt<ApiClient>();
|
||||
authService = getIt<AuthService>();
|
||||
licenseService = getIt<LicenseService>();
|
||||
companyService = getIt<CompanyService>();
|
||||
|
||||
Reference in New Issue
Block a user