Files
zellyy-finance/src/lib/supabase/tests/index.ts
gpt-engineer-app[bot] f9aec98a45 Refactor: Split Supabase tests
Splits the Supabase tests into smaller modules for better readability and maintainability.
2025-03-15 12:35:59 +00:00

109 lines
4.1 KiB
TypeScript

import { getSupabaseUrl, getSupabaseKey, getOriginalSupabaseUrl, isCorsProxyEnabled, getProxyType } from '../config';
import { testAuthService } from './authTests';
import { testRestApi } from './apiTests';
import { testDatabaseConnection } from './databaseTests';
import { ConnectionTestResult, LoginTestResult } from './types';
export { testSupabaseLogin } from './authTests';
// API 테스트 도우미 함수
export const testSupabaseConnection = async (): Promise<ConnectionTestResult> => {
const originalUrl = getOriginalSupabaseUrl();
const proxyUrl = getSupabaseUrl();
const usingProxy = isCorsProxyEnabled();
const proxyType = getProxyType();
const supabaseKey = getSupabaseKey();
const results: ConnectionTestResult = {
url: originalUrl, // 원본 URL
proxyUrl: proxyUrl, // 프록시 적용된 URL
usingProxy: usingProxy, // 프록시 사용 여부
proxyType: proxyType, // 프록시 유형
client: !!supabase,
restApi: false,
auth: false,
database: false,
errors: [] as string[],
debugInfo: {
originalUrl,
proxyUrl,
usingProxy,
proxyType,
keyLength: supabaseKey.length,
browserInfo: navigator.userAgent,
timestamp: new Date().toISOString(),
backupProxySuccess: false,
lastErrorDetails: ''
}
};
console.log('연결 테스트 시작 - 설정 정보:', {
originalUrl,
proxyUrl,
usingProxy,
proxyType
});
try {
// 1. REST API 테스트
try {
const apiTestResult = await testRestApi(proxyUrl, originalUrl, supabaseKey, proxyType);
results.restApi = apiTestResult.success;
if (!apiTestResult.success) {
results.debugInfo.lastErrorDetails = apiTestResult.lastErrorDetails || '';
results.debugInfo.backupProxySuccess = !!apiTestResult.backupProxySuccess;
if (apiTestResult.backupProxySuccess && apiTestResult.recommendedProxy) {
results.errors.push(`REST API 성공: ${apiTestResult.recommendedProxy} 프록시 사용 시 정상 작동합니다. 설정에서 이 프록시를 선택해보세요.`);
} else if (usingProxy) {
results.errors.push(`REST API 오류: ${apiTestResult.lastErrorDetails || '응답 없음'} - 다른 프록시 옵션도 모두 실패했습니다.`);
} else {
results.errors.push(`REST API 오류: ${apiTestResult.lastErrorDetails || '응답 없음'} - CORS 프록시 활성화를 시도해보세요.`);
}
}
} catch (err: any) {
results.errors.push(`REST API 예외: ${err.message || '알 수 없는 오류'}`);
console.error('REST API 테스트 중 예외:', err);
}
// 2. 인증 서비스 테스트
try {
const authTestResult = await testAuthService();
results.auth = authTestResult.success;
if (!authTestResult.success) {
results.errors.push(`인증 오류: ${authTestResult.error?.message || '알 수 없는 오류'}`);
}
} catch (err: any) {
results.errors.push(`인증 예외: ${err.message || '알 수 없는 오류'}`);
console.error('인증 테스트 중 예외:', err);
}
// 3. 데이터베이스 연결 테스트
try {
const dbTestResult = await testDatabaseConnection();
results.database = dbTestResult.success;
if (!dbTestResult.success) {
results.errors.push(`데이터베이스 오류: ${dbTestResult.error?.message || '알 수 없는 오류'}`);
}
} catch (err: any) {
results.errors.push(`데이터베이스 예외: ${err.message || '알 수 없는 오류'}`);
console.error('데이터베이스 테스트 중 예외:', err);
}
// 오류가 없는 경우 메시지 추가
if (results.errors.length === 0) {
results.errors.push('모든 테스트 통과! 연결 상태가 정상입니다.');
}
} catch (err: any) {
results.errors.push(`테스트 실행 예외: ${err.message || '알 수 없는 오류'}`);
console.error('전체 테스트 실행 중 예외:', err);
}
console.log('Supabase 연결 테스트 결과:', results);
return results;
};