UNPKG

unpak.js

Version:

Modern TypeScript library for reading Unreal Engine pak files and assets, inspired by CUE4Parse

214 lines (182 loc) 8.11 kB
/** * Tests for Database and Multi-Tenant features (Phase 12) only * Note: Simplified to avoid complex UObject dependencies during testing */ // Create mock types to avoid UObject dependencies interface MockBlueprintPlugin { PluginName: { text: string }; PluginVersion: string; PluginDescription: string; RequiredEngineVersion: string; SupportedTargetPlatforms: string[]; validateCompatibility(engineVersion: string, platform: string): { isCompatible: boolean; errors: string[]; warnings: string[]; }; getMarketplaceMetadata(): { pluginName: string; version: string; supportedPlatforms: string[]; }; } // Simple mock implementation function createMockBlueprintPlugin(): MockBlueprintPlugin { return { PluginName: { text: '' }, PluginVersion: '', PluginDescription: '', RequiredEngineVersion: '', SupportedTargetPlatforms: [], validateCompatibility(engineVersion: string, platform: string) { const required = this.RequiredEngineVersion.split('.').map(Number); const target = engineVersion.split('.').map(Number); const isCompatible = required[0] === target[0] && target[1] >= required[1]; return { isCompatible, errors: isCompatible ? [] : [`Engine version mismatch`], warnings: [] }; }, getMarketplaceMetadata() { return { pluginName: this.PluginName.text, version: this.PluginVersion, supportedPlatforms: this.SupportedTargetPlatforms }; } }; } import { UnpakDatabaseProvider } from '../src/api/database/UnpakDatabaseProvider'; import { MultiTenantManager } from '../src/api/tenancy/MultiTenantManager'; describe('Phase 9 & 12 Roadmap Features', () => { describe('MockBlueprintPlugin (Phase 9 concept)', () => { let plugin: MockBlueprintPlugin; beforeEach(() => { plugin = createMockBlueprintPlugin(); plugin.PluginName.text = 'TestPlugin'; plugin.PluginVersion = '1.0.0'; plugin.RequiredEngineVersion = '5.1.0'; plugin.SupportedTargetPlatforms = ['Win64', 'Mac']; }); test('should validate engine compatibility correctly', () => { const compatible = plugin.validateCompatibility('5.3.0', 'Win64'); expect(compatible.isCompatible).toBe(true); expect(compatible.errors).toHaveLength(0); }); test('should detect incompatible engine version', () => { const incompatible = plugin.validateCompatibility('4.27.0', 'Win64'); expect(incompatible.isCompatible).toBe(false); expect(incompatible.errors.length).toBeGreaterThan(0); }); test('should return marketplace metadata', () => { const metadata = plugin.getMarketplaceMetadata(); expect(metadata.pluginName).toBe('TestPlugin'); expect(metadata.version).toBe('1.0.0'); expect(metadata.supportedPlatforms).toContain('Win64'); }); }); describe('UnpakDatabaseProvider (Phase 12)', () => { let database: UnpakDatabaseProvider; beforeEach(async () => { database = new UnpakDatabaseProvider({ provider: 'sqlite', enableQueryLog: false }); await database.initialize({ provider: 'sqlite', connectionString: ':memory:' }); }); test('should initialize successfully', async () => { expect(database).toBeDefined(); }); test('should store and retrieve asset metadata', async () => { const metadata = { assetId: 'test_asset_001', name: 'TestAsset', path: '/Test/Asset.uasset', type: 'UStaticMesh', size: 1024, tenantId: 'test_tenant' }; const assetId = await database.storeAssetMetadata(metadata); expect(assetId).toBe('test_asset_001'); }); test('should store performance metrics', async () => { const metrics = { metricId: 'test_metric_001', operationType: 'asset_parsing', durationMs: 1500, memoryUsageMb: 256, tenantId: 'test_tenant', timestamp: new Date().toISOString() }; await expect(database.storePerformanceMetrics(metrics)).resolves.toBeUndefined(); }); }); describe('MultiTenantManager (Phase 12)', () => { let database: UnpakDatabaseProvider; let multiTenant: MultiTenantManager; beforeEach(async () => { database = new UnpakDatabaseProvider({ provider: 'sqlite', enableQueryLog: false }); await database.initialize({ provider: 'sqlite', connectionString: ':memory:' }); multiTenant = new MultiTenantManager(database); await multiTenant.initialize(); }); test('should create tenant with different plans', async () => { const basicTenant = await multiTenant.createTenant({ tenantId: 'basic_tenant', name: 'Basic Tenant', plan: 'basic' }); const enterpriseTenant = await multiTenant.createTenant({ tenantId: 'enterprise_tenant', name: 'Enterprise Tenant', plan: 'enterprise' }); expect(basicTenant.plan).toBe('basic'); expect(basicTenant.resourceLimits.maxMemoryMB).toBe(2048); expect(enterpriseTenant.plan).toBe('enterprise'); expect(enterpriseTenant.resourceLimits.maxMemoryMB).toBe(32768); }); test('should create and validate sessions', async () => { await multiTenant.createTenant({ tenantId: 'session_test', name: 'Session Test Tenant', plan: 'professional' }); const session = await multiTenant.createSession('session_test', 'user_001'); expect(session.tenantId).toBe('session_test'); expect(session.userId).toBe('user_001'); expect(session.sessionId).toMatch(/^sess_/); // Validate session const validatedSession = multiTenant.validateSession(session.sessionId); expect(validatedSession.sessionId).toBe(session.sessionId); }); test('should check resource limits correctly', async () => { await multiTenant.createTenant({ tenantId: 'resource_test', name: 'Resource Test Tenant', plan: 'basic' // 2GB memory limit }); // Should allow small operation const smallOperation = multiTenant.checkResourceLimits('resource_test', { memoryRequired: 512 // 512MB }); expect(smallOperation.allowed).toBe(true); // Should reject large operation const largeOperation = multiTenant.checkResourceLimits('resource_test', { memoryRequired: 4096 // 4GB (exceeds 2GB limit) }); expect(largeOperation.allowed).toBe(false); expect(largeOperation.reason).toContain('Memory limit exceeded'); }); }); });