d3ro-voice/packages/api-client/__tests__/client.test.ts
2026-08-29 18:33:45 +09:00

69 lines
2.3 KiB
TypeScript

// packages/api-client/__tests__/client.test.ts
// createD3roSupabaseClient 팩토리 유닛 테스트
import { describe, it, expect } from 'vitest'
import {
createD3roSupabaseClient,
isClientConfigured,
SupabaseConfigurationError,
} from '../src/client'
describe('createD3roSupabaseClient', () => {
it('URL과 key가 없으면 설정 오류로 즉시 실패한다', () => {
expect(() => createD3roSupabaseClient({ url: undefined, anonKey: undefined }))
.toThrow(SupabaseConfigurationError)
})
it('URL이나 key 중 하나만 있거나 공백이면 설정 오류로 즉시 실패한다', () => {
expect(() => createD3roSupabaseClient({
url: 'https://real.supabase.co',
anonKey: undefined,
})).toThrow(SupabaseConfigurationError)
expect(() => createD3roSupabaseClient({
url: ' ',
anonKey: 'anon-key',
})).toThrow(SupabaseConfigurationError)
})
it('URL과 key가 모두 있으면 실제 클라이언트를 생성한다', () => {
const client = createD3roSupabaseClient({
url: 'https://real.supabase.co',
anonKey: 'real-anon-key'
})
expect(client).toBeDefined()
expect(typeof client.auth.getSession).toBe('function')
})
it('auth 옵션을 주입할 수 있다', () => {
const client = createD3roSupabaseClient({
url: 'https://real.supabase.co',
anonKey: 'real-anon-key',
auth: { persistSession: false, autoRefreshToken: false }
})
expect(client).toBeDefined()
})
})
describe('isClientConfigured', () => {
it('URL과 key가 모두 있으면 true', () => {
expect(isClientConfigured({ url: 'https://x.supabase.co', anonKey: 'k' })).toBe(true)
})
it('URL만 있으면 false', () => {
expect(isClientConfigured({ url: 'https://x.supabase.co', anonKey: undefined })).toBe(false)
})
it('key만 있으면 false', () => {
expect(isClientConfigured({ url: undefined, anonKey: 'k' })).toBe(false)
})
it('둘 다 없으면 false', () => {
expect(isClientConfigured({ url: undefined, anonKey: undefined })).toBe(false)
})
it('빈 문자열은 false로 처리된다', () => {
expect(isClientConfigured({ url: '', anonKey: 'k' })).toBe(false)
expect(isClientConfigured({ url: 'https://x.supabase.co', anonKey: '' })).toBe(false)
expect(isClientConfigured({ url: ' ', anonKey: 'k' })).toBe(false)
})
})