Add mock data and unit tests for Channels and Members APIs

This commit is contained in:
2025-12-07 04:41:41 -05:00
parent 4673547b95
commit a88fa40ba2
12 changed files with 1377 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
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');
});
});
});