import {describe, expect, it} from 'bun:test'; import {PCastHttpRequests, type ApplicationCredentials} from '../../../src/apis/PCastRequests'; describe('PCastHttpRequests', () => { const mockCredentials: ApplicationCredentials = { id: 'test-app-id', secret: 'test-app-secret' }; describe('when instantiating with valid credentials', () => { it('should create an instance successfully', () => { const requests = new PCastHttpRequests('https://pcast.example.com', mockCredentials); expect(requests).toBeInstanceOf(PCastHttpRequests); }); it('should expose the application id as tenancy', () => { const requests = new PCastHttpRequests('https://pcast.example.com', mockCredentials); expect(requests.tenancy).toBe('test-app-id'); }); }); describe('when providing custom options', () => { it('should accept a custom request timeout duration', () => { const requests = new PCastHttpRequests('https://pcast.example.com', mockCredentials, { requestTimeoutDuration: 5000 }); expect(requests).toBeInstanceOf(PCastHttpRequests); }); }); describe('when encoding authorization credentials', () => { it('should generate correct base64 encoded "id:secret" string', () => { const expectedCredentials = 'test-app-id:test-app-secret'; const expectedBase64 = typeof btoa === 'function' ? btoa(expectedCredentials) : Buffer.from(expectedCredentials, 'utf-8').toString('base64'); expect(expectedBase64).toBe('dGVzdC1hcHAtaWQ6dGVzdC1hcHAtc2VjcmV0'); }); }); }); describe('ApplicationCredentials', () => { describe('when defining credentials', () => { it('should require both id and secret properties', () => { const credentials: ApplicationCredentials = { id: 'my-app', secret: 'my-secret' }; expect(credentials.id).toBe('my-app'); expect(credentials.secret).toBe('my-secret'); }); }); });