- 모든 서비스 메서드 시그니처를 실제 구현에 맞게 수정 - TestDataGenerator 제거하고 직접 객체 생성으로 변경 - 모델 필드명 및 타입 불일치 수정 - 불필요한 Either 패턴 사용 제거 - null safety 관련 이슈 해결 수정된 파일: - test/integration/screens/company_integration_test.dart - test/integration/screens/equipment_integration_test.dart - test/integration/screens/user_integration_test.dart - test/integration/screens/login_integration_test.dart
250 lines
8.1 KiB
Dart
250 lines
8.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import 'package:superport/models/warehouse_location_model.dart';
|
|
import 'package:superport/models/address_model.dart';
|
|
import 'package:superport/services/warehouse_service.dart';
|
|
import 'package:superport/services/company_service.dart';
|
|
import 'test_helper.dart';
|
|
|
|
void main() {
|
|
late WarehouseService warehouseService;
|
|
late CompanyService companyService;
|
|
String? authToken;
|
|
int? createdWarehouseId;
|
|
int? testCompanyId;
|
|
|
|
setUpAll(() async {
|
|
await RealApiTestHelper.setupTestEnvironment();
|
|
|
|
// 로그인하여 인증 토큰 획득
|
|
authToken = await RealApiTestHelper.loginAndGetToken();
|
|
expect(authToken, isNotNull, reason: '로그인에 실패했습니다');
|
|
|
|
// 서비스 가져오기
|
|
warehouseService = GetIt.instance<WarehouseService>();
|
|
companyService = GetIt.instance<CompanyService>();
|
|
|
|
// 테스트용 회사 가져오기
|
|
final companies = await companyService.getCompanies(page: 1, perPage: 1);
|
|
if (companies.isNotEmpty) {
|
|
testCompanyId = companies.first.id;
|
|
}
|
|
});
|
|
|
|
tearDownAll(() async {
|
|
await RealApiTestHelper.teardownTestEnvironment();
|
|
});
|
|
|
|
group('Warehouse CRUD API 테스트', skip: 'Real API tests - skipping in CI', () {
|
|
test('창고 목록 조회', () async {
|
|
final warehouses = await warehouseService.getWarehouseLocations(
|
|
page: 1,
|
|
perPage: 10,
|
|
);
|
|
|
|
expect(warehouses, isNotNull);
|
|
expect(warehouses, isA<List<WarehouseLocation>>());
|
|
|
|
if (warehouses.isNotEmpty) {
|
|
final firstWarehouse = warehouses.first;
|
|
expect(firstWarehouse.id, isNotNull);
|
|
expect(firstWarehouse.name, isNotEmpty);
|
|
expect(firstWarehouse.address, isNotNull);
|
|
}
|
|
});
|
|
|
|
test('창고 생성', () async {
|
|
if (testCompanyId == null) {
|
|
// 창고를 생성할 회사가 없습니다
|
|
return;
|
|
}
|
|
|
|
final newWarehouse = WarehouseLocation(
|
|
id: 0, // 임시 ID
|
|
name: 'Integration Test Warehouse \${DateTime.now().millisecondsSinceEpoch}',
|
|
address: Address(
|
|
zipCode: '12345',
|
|
region: '서울시 강남구',
|
|
detailAddress: '테스트로 123',
|
|
),
|
|
remark: '통합 테스트용 창고',
|
|
);
|
|
|
|
final createdWarehouse = await warehouseService.createWarehouseLocation(newWarehouse);
|
|
|
|
expect(createdWarehouse, isNotNull);
|
|
expect(createdWarehouse.id, isNotNull);
|
|
expect(createdWarehouse.name, equals(newWarehouse.name));
|
|
expect(createdWarehouse.address.detailAddress, equals(newWarehouse.address.detailAddress));
|
|
|
|
createdWarehouseId = createdWarehouse.id;
|
|
});
|
|
|
|
test('창고 상세 조회', () async {
|
|
if (createdWarehouseId == null) {
|
|
// 창고 목록에서 첫 번째 창고 ID 사용
|
|
final warehouses = await warehouseService.getWarehouseLocations(page: 1, perPage: 1);
|
|
if (warehouses.isEmpty) {
|
|
// 조회할 창고가 없습니다
|
|
return;
|
|
}
|
|
createdWarehouseId = warehouses.first.id;
|
|
}
|
|
|
|
final warehouse = await warehouseService.getWarehouseLocationById(createdWarehouseId!);
|
|
|
|
expect(warehouse, isNotNull);
|
|
expect(warehouse.id, equals(createdWarehouseId));
|
|
expect(warehouse.name, isNotEmpty);
|
|
expect(warehouse.address.detailAddress, isNotEmpty);
|
|
});
|
|
|
|
test('창고 정보 수정', () async {
|
|
if (createdWarehouseId == null) {
|
|
// 수정할 창고가 없습니다
|
|
return;
|
|
}
|
|
|
|
// 먼저 현재 창고 정보 조회
|
|
final currentWarehouse = await warehouseService.getWarehouseLocationById(createdWarehouseId!);
|
|
|
|
// 수정할 정보
|
|
final updatedWarehouse = currentWarehouse.copyWith(
|
|
name: '\${currentWarehouse.name} - Updated',
|
|
address: Address(
|
|
zipCode: '54321',
|
|
region: '서울시 서초구',
|
|
detailAddress: '수정로 456',
|
|
),
|
|
remark: '수정된 창고 정보',
|
|
);
|
|
|
|
final result = await warehouseService.updateWarehouseLocation(updatedWarehouse);
|
|
|
|
expect(result, isNotNull);
|
|
expect(result.id, equals(createdWarehouseId));
|
|
expect(result.name, contains('Updated'));
|
|
expect(result.address.detailAddress, equals('수정로 456'));
|
|
});
|
|
|
|
test('활성 창고만 조회', () async {
|
|
final activeWarehouses = await warehouseService.getWarehouseLocations(
|
|
page: 1,
|
|
perPage: 10,
|
|
isActive: true,
|
|
);
|
|
|
|
expect(activeWarehouses, isNotNull);
|
|
expect(activeWarehouses, isA<List<WarehouseLocation>>());
|
|
|
|
// WarehouseLocation 모델에는 isActive 필드가 없으므로 단순히 조회만 확인
|
|
if (activeWarehouses.isNotEmpty) {
|
|
expect(activeWarehouses.first.name, isNotEmpty);
|
|
}
|
|
});
|
|
|
|
test('창고별 장비 목록 조회', () async {
|
|
if (createdWarehouseId == null) {
|
|
// 장비를 조회할 창고가 없습니다
|
|
return;
|
|
}
|
|
|
|
try {
|
|
final equipment = await warehouseService.getWarehouseEquipment(
|
|
createdWarehouseId!,
|
|
page: 1,
|
|
perPage: 10,
|
|
);
|
|
|
|
expect(equipment, isNotNull);
|
|
expect(equipment, isA<List<Map<String, dynamic>>>());
|
|
// 장비 목록이 있다면 각 장비가 필수 필드를 가지고 있는지 확인
|
|
if (equipment.isNotEmpty) {
|
|
final firstEquipment = equipment.first;
|
|
expect(firstEquipment.containsKey('id'), isTrue);
|
|
expect(firstEquipment.containsKey('equipmentName'), isTrue);
|
|
}
|
|
} catch (e) {
|
|
// 창고별 장비 조회 실패: \$e
|
|
}
|
|
});
|
|
|
|
test('창고 용량 정보 조회', () async {
|
|
if (createdWarehouseId == null) {
|
|
// 용량을 확인할 창고가 없습니다
|
|
return;
|
|
}
|
|
|
|
try {
|
|
final capacityInfo = await warehouseService.getWarehouseCapacity(createdWarehouseId!);
|
|
|
|
expect(capacityInfo, isNotNull);
|
|
// 용량 정보 검증은 WarehouseCapacityInfo 모델 구조에 따라 다름
|
|
} catch (e) {
|
|
// 창고 용량 정보 조회 실패: \$e
|
|
}
|
|
});
|
|
|
|
test('사용 중인 창고 위치 목록 조회', () async {
|
|
final inUseWarehouses = await warehouseService.getInUseWarehouseLocations();
|
|
|
|
expect(inUseWarehouses, isNotNull);
|
|
expect(inUseWarehouses, isA<List<WarehouseLocation>>());
|
|
|
|
if (inUseWarehouses.isNotEmpty) {
|
|
final firstWarehouse = inUseWarehouses.first;
|
|
expect(firstWarehouse.id, isNotNull);
|
|
expect(firstWarehouse.name, isNotEmpty);
|
|
}
|
|
});
|
|
|
|
test('창고 삭제', () async {
|
|
if (createdWarehouseId == null) {
|
|
// 삭제할 창고가 없습니다
|
|
return;
|
|
}
|
|
|
|
// 삭제 실행
|
|
await warehouseService.deleteWarehouseLocation(createdWarehouseId!);
|
|
|
|
// 삭제 확인 (404 에러 예상)
|
|
try {
|
|
await warehouseService.getWarehouseLocationById(createdWarehouseId!);
|
|
fail('삭제된 창고가 여전히 조회됩니다');
|
|
} catch (e) {
|
|
// 삭제 성공 - 404 에러가 발생해야 함
|
|
expect(e.toString(), isNotEmpty);
|
|
}
|
|
});
|
|
|
|
test('잘못된 ID로 창고 조회 시 에러', () async {
|
|
try {
|
|
await warehouseService.getWarehouseLocationById(999999);
|
|
fail('존재하지 않는 창고가 조회되었습니다');
|
|
} catch (e) {
|
|
// 에러가 발생해야 정상
|
|
expect(e.toString(), isNotEmpty);
|
|
}
|
|
});
|
|
|
|
test('필수 정보 없이 창고 생성 시 에러', () async {
|
|
try {
|
|
final invalidWarehouse = WarehouseLocation(
|
|
id: 0,
|
|
name: '', // 빈 이름
|
|
address: Address(
|
|
zipCode: '',
|
|
region: '',
|
|
detailAddress: '', // 빈 주소
|
|
),
|
|
);
|
|
|
|
await warehouseService.createWarehouseLocation(invalidWarehouse);
|
|
fail('잘못된 데이터로 창고가 생성되었습니다');
|
|
} catch (e) {
|
|
// 에러가 발생해야 정상
|
|
expect(e.toString(), isNotEmpty);
|
|
}
|
|
});
|
|
});
|
|
} |