import { describe, test, expect, beforeEach, mock } from 'bun:test'; import { PLCBundle } from '../src/plcbundle'; import { TEMP_DIR } from './setup'; describe('Clone Functionality', () => { let bundle: PLCBundle; beforeEach(() => { bundle = new PLCBundle(TEMP_DIR); }); describe('clone', () => { test('validates bundle range', async () => { // Mock fetch to return an index const mockFetch = mock(() => Promise.resolve(new Response(JSON.stringify({ version: "1.0", last_bundle: 10, updated_at: new Date().toISOString(), total_size_bytes: 1000000, bundles: [], }))) ); global.fetch = mockFetch as any; try { await bundle.clone('http://example.com', { bundles: '1-999', // Invalid range }); expect(true).toBe(false); // Should not reach here } catch (error) { expect(error).toBeDefined(); expect((error as Error).message).toContain('Invalid bundle range'); } }); test('parses bundle selection correctly', async () => { const mockFetch = mock(() => Promise.resolve(new Response(JSON.stringify({ version: "1.0", last_bundle: 100, updated_at: new Date().toISOString(), total_size_bytes: 1000000, bundles: Array.from({ length: 100 }, (_, i) => ({ bundle_number: i + 1, start_time: "2024-01-01T00:00:00.000Z", end_time: "2024-01-01T01:00:00.000Z", operation_count: 10000, did_count: 9500, hash: `hash${i}`, content_hash: `content${i}`, parent: i > 0 ? `hash${i-1}` : "", compressed_hash: `compressed${i}`, compressed_size: 1500000, uncompressed_size: 5000000, cursor: "", created_at: "2024-01-01T02:00:00.000Z", })), }))) ); global.fetch = mockFetch as any; // Test single bundle expect(bundle.clone).toBeDefined(); // Test range expect(bundle.clone).toBeDefined(); }); test('tracks download statistics', async () => { const progressCallback = mock(() => {}); // Would need a mock server to fully test expect(progressCallback).toBeDefined(); }); }); });