Files
superport/test/debug_api_counts_test.dart

148 lines
4.9 KiB
Dart

import 'package:dio/dio.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:superport/core/config/environment.dart';
void main() {
late Dio dio;
setUpAll(() {
dio = Dio(BaseOptions(
baseUrl: Environment.apiBaseUrl,
connectTimeout: const Duration(seconds: 30),
receiveTimeout: const Duration(seconds: 30),
));
});
group('API Count Debugging', () {
test('Check all entity counts from API', () async {
// 먼저 로그인
final loginResponse = await dio.post('/auth/login', data: {
'email': 'admin@example.com',
'password': 'password123',
});
final token = loginResponse.data['data']['access_token'];
dio.options.headers['Authorization'] = 'Bearer $token';
print('\n========== API 카운트 디버깅 ==========\n');
// 1. 장비 개수 확인
try {
final equipmentResponse = await dio.get('/equipment', queryParameters: {
'page': 1,
'per_page': 1,
});
final equipmentTotal = equipmentResponse.data['pagination']['total'];
print('✅ 장비: $equipmentTotal개');
} catch (e) {
print('❌ 장비 조회 실패: $e');
}
// 2. 입고지 개수 확인
try {
final warehouseResponse = await dio.get('/warehouse-locations', queryParameters: {
'page': 1,
'per_page': 1,
});
final warehouseTotal = warehouseResponse.data['pagination']['total'];
print('✅ 입고지: $warehouseTotal개');
} catch (e) {
print('❌ 입고지 조회 실패: $e');
}
// 3. 회사 개수 확인
try {
final companyResponse = await dio.get('/companies', queryParameters: {
'page': 1,
'per_page': 1,
});
final companyTotal = companyResponse.data['pagination']['total'];
print('✅ 회사: $companyTotal개');
// 회사별 지점 개수 확인
final allCompaniesResponse = await dio.get('/companies', queryParameters: {
'page': 1,
'per_page': 100,
});
int totalBranches = 0;
final companies = allCompaniesResponse.data['data'] as List;
for (var company in companies) {
final branches = company['branches'] as List?;
if (branches != null) {
totalBranches += branches.length;
}
}
print(' └─ 지점: $totalBranches개');
print(' └─ 회사 + 지점 총합: ${companyTotal + totalBranches}');
// 실제 회사 목록 확인
print('\n 회사 목록 샘플:');
for (var i = 0; i < companies.length && i < 5; i++) {
print(' - ${companies[i]['name']} (ID: ${companies[i]['id']})');
}
if (companies.length > 5) {
print(' ... 그 외 ${companies.length - 5}');
}
} catch (e) {
print('❌ 회사 조회 실패: $e');
}
// 4. 유지보수 개수 확인
try {
final licenseResponse = await dio.get('/licenses', queryParameters: {
'page': 1,
'per_page': 1,
});
final licenseTotal = licenseResponse.data['pagination']['total'];
print('✅ 유지보수: $licenseTotal개');
} catch (e) {
print('❌ 유지보수 조회 실패: $e');
}
print('\n========================================\n');
print('\n========== 전체 데이터 조회 ==========\n');
// 입고지 전체 데이터 조회해서 실제 개수 확인
try {
final warehouseAllResponse = await dio.get('/warehouse-locations', queryParameters: {
'page': 1,
'per_page': 100,
});
final warehouseData = warehouseAllResponse.data['data'] as List;
print('입고지 실제 반환된 데이터 개수: ${warehouseData.length}');
print('입고지 pagination.total: ${warehouseAllResponse.data['pagination']['total']}');
// ID 중복 확인
final warehouseIds = <int>{};
final duplicateIds = <int>{};
for (var warehouse in warehouseData) {
final id = warehouse['id'] as int;
if (warehouseIds.contains(id)) {
duplicateIds.add(id);
}
warehouseIds.add(id);
}
if (duplicateIds.isNotEmpty) {
print('⚠️ 중복된 ID 발견: $duplicateIds');
} else {
print('✅ ID 중복 없음');
}
// 각 입고지 정보 출력
for (var i = 0; i < warehouseData.length && i < 10; i++) {
print(' - ${warehouseData[i]['name']} (ID: ${warehouseData[i]['id']})');
}
if (warehouseData.length > 10) {
print(' ... 그 외 ${warehouseData.length - 10}');
}
} catch (e) {
print('❌ 입고지 전체 조회 실패: $e');
}
print('\n========================================\n');
});
});
}