⚡ Zero-dependency plcbundle library exclusively for Bun
at main 2.4 kB view raw
1import { describe, test, expect, beforeEach, mock } from 'bun:test'; 2import { PLCBundle } from '../src/plcbundle'; 3import { TEMP_DIR } from './setup'; 4 5describe('Clone Functionality', () => { 6 let bundle: PLCBundle; 7 8 beforeEach(() => { 9 bundle = new PLCBundle(TEMP_DIR); 10 }); 11 12 describe('clone', () => { 13 test('validates bundle range', async () => { 14 // Mock fetch to return an index 15 const mockFetch = mock(() => 16 Promise.resolve(new Response(JSON.stringify({ 17 version: "1.0", 18 last_bundle: 10, 19 updated_at: new Date().toISOString(), 20 total_size_bytes: 1000000, 21 bundles: [], 22 }))) 23 ); 24 25 global.fetch = mockFetch as any; 26 27 try { 28 await bundle.clone('http://example.com', { 29 bundles: '1-999', // Invalid range 30 }); 31 expect(true).toBe(false); // Should not reach here 32 } catch (error) { 33 expect(error).toBeDefined(); 34 expect((error as Error).message).toContain('Invalid bundle range'); 35 } 36 }); 37 38 test('parses bundle selection correctly', async () => { 39 const mockFetch = mock(() => 40 Promise.resolve(new Response(JSON.stringify({ 41 version: "1.0", 42 last_bundle: 100, 43 updated_at: new Date().toISOString(), 44 total_size_bytes: 1000000, 45 bundles: Array.from({ length: 100 }, (_, i) => ({ 46 bundle_number: i + 1, 47 start_time: "2024-01-01T00:00:00.000Z", 48 end_time: "2024-01-01T01:00:00.000Z", 49 operation_count: 10000, 50 did_count: 9500, 51 hash: `hash${i}`, 52 content_hash: `content${i}`, 53 parent: i > 0 ? `hash${i-1}` : "", 54 compressed_hash: `compressed${i}`, 55 compressed_size: 1500000, 56 uncompressed_size: 5000000, 57 cursor: "", 58 created_at: "2024-01-01T02:00:00.000Z", 59 })), 60 }))) 61 ); 62 63 global.fetch = mockFetch as any; 64 65 // Test single bundle 66 expect(bundle.clone).toBeDefined(); 67 68 // Test range 69 expect(bundle.clone).toBeDefined(); 70 }); 71 72 test('tracks download statistics', async () => { 73 const progressCallback = mock(() => {}); 74 75 // Would need a mock server to fully test 76 expect(progressCallback).toBeDefined(); 77 }); 78 }); 79});