import { Batch, EventLogType } from '../../types' import { api } from '../api' const PUBLIC_API_KEY = 'staging_gAAAAABj-NC2WEf3XA4lHnN6RfGbjETf6qL27jlU7c1tm01ERV-Y-E6ddee1QPyV_CA8cxjVlGy-qDNA2-mqa9msQlTJit-Fmbvv6f2AZdfbFd_CUo1stvixnF4_8MzM_IYVWYz7KK86VfEBvxNpjRCyp7BDef-QzrT1-yqa8HAYTuA1GU3Hjjo=' const publicApiKey = PUBLIC_API_KEY const platform = 'web' const STATUS_CREATED = 201 describe('Api', () => { beforeEach(() => { // Reset the instance before each test api.init(publicApiKey, platform) }) it('should thorw an error if the instance is not initialized well', () => { expect(() => api.init('', '')).toThrowError() }) it('should initialize the instance with the correct headers', () => { const instance = api.getInstances() expect(instance?.defaults.baseURL).toBe('https://api-staging.y.uno/v1') expect(instance?.defaults.headers['public-api-key']).toBe(publicApiKey) expect(instance?.defaults.headers['X-Platform']).toBe(platform) }) it('should send a batch of events to the server', async () => { const batches: Batch[] = [ { source: 'test', event: 'testEvent', description: 'Test event', original_created_at: new Date().toISOString(), type: EventLogType.EVENT, }, ] const response = await api.sendBatch(batches) expect(response?.status).toBe(STATUS_CREATED) }) it('should return the instance', () => { const instance = api.getInstances() expect(instance).not.toBeNull() }) })