/** * Client unit tests */ import { describe, it, expect } from 'vitest'; import { IyzicoClient } from '../../src/client'; describe('IyzicoClient', () => { const apiKey = 'test-api-key'; const secretKey = 'test-secret-key'; it('should create a client with required config', () => { const client = new IyzicoClient({ apiKey, secretKey, }); expect(client.apiKey).toBe(apiKey); expect(client.secretKey).toBe(secretKey); expect(client.baseUrl).toBe('https://sandbox-api.iyzipay.com'); expect(client.locale).toBe('tr'); }); it('should throw error when apiKey is missing', () => { expect(() => { new IyzicoClient({ apiKey: '', secretKey, } as any); }).toThrow('API key is required'); }); it('should throw error when secretKey is missing', () => { expect(() => { new IyzicoClient({ apiKey, secretKey: '', } as any); }).toThrow('Secret key is required'); }); it('should use custom baseUrl when provided', () => { const customUrl = 'https://api.custom.com'; const client = new IyzicoClient({ apiKey, secretKey, baseUrl: customUrl, }); expect(client.baseUrl).toBe(customUrl); }); it('should use custom locale when provided', () => { const client = new IyzicoClient({ apiKey, secretKey, locale: 'en', }); expect(client.locale).toBe('en'); }); it('should initialize all services', () => { const client = new IyzicoClient({ apiKey, secretKey, }); expect(client.payment).toBeDefined(); expect(client.binCheck).toBeDefined(); expect(client.cancelRefund).toBeDefined(); expect(client.cardStorage).toBeDefined(); expect(client.reporting).toBeDefined(); }); it('should return locale via getLocale()', () => { const client = new IyzicoClient({ apiKey, secretKey, locale: 'en', }); expect(client.getLocale()).toBe('en'); }); it('should return baseUrl via getBaseUrl()', () => { const customUrl = 'https://api.custom.com'; const client = new IyzicoClient({ apiKey, secretKey, baseUrl: customUrl, }); expect(client.getBaseUrl()).toBe(customUrl); }); });