import { describe, it, expect } from 'vitest'; import { BACKEND_REGISTRY, BackendType } from './registry'; const EXPECTED_BACKENDS: BackendType[] = ['azureblob', 's3', 's3-compatible', 'onedrive', 'sftp', 'gcs', 'b2']; describe('Backend Schema Registry', () => { it('exports all three required backend types', () => { for (const backend of EXPECTED_BACKENDS) { expect(BACKEND_REGISTRY[backend]).toBeDefined(); } }); it('each backend has at least one field definition', () => { for (const backend of EXPECTED_BACKENDS) { expect(BACKEND_REGISTRY[backend].fields.length).toBeGreaterThan(0); } }); it('each FieldDef has a non-empty key (snake_case, no camelCase)', () => { for (const backend of EXPECTED_BACKENDS) { for (const field of BACKEND_REGISTRY[backend].fields) { expect(field.key).toBeTruthy(); // Reject camelCase — rclone keys are snake_case or lowercase expect(field.key).not.toMatch(/[A-Z]/); } } }); it('each FieldDef has a non-empty label', () => { for (const backend of EXPECTED_BACKENDS) { for (const field of BACKEND_REGISTRY[backend].fields) { expect(field.label).toBeTruthy(); } } }); it('Azure Blob has account field (required)', () => { const accountField = BACKEND_REGISTRY.azureblob.fields.find(f => f.key === 'account'); expect(accountField).toBeDefined(); expect(accountField!.required).toBe(true); }); it('S3 has access_key_id, secret_access_key, and region fields', () => { const keys = BACKEND_REGISTRY.s3.fields.map(f => f.key); expect(keys).toContain('access_key_id'); expect(keys).toContain('secret_access_key'); expect(keys).toContain('region'); }); it('S3-compatible has endpoint field (required)', () => { const endpointField = BACKEND_REGISTRY['s3-compatible'].fields.find(f => f.key === 'endpoint'); expect(endpointField).toBeDefined(); expect(endpointField!.required).toBe(true); }); it('each backend entry has displayName and description metadata', () => { for (const backend of EXPECTED_BACKENDS) { expect(BACKEND_REGISTRY[backend].displayName).toBeTruthy(); expect(BACKEND_REGISTRY[backend].description).toBeTruthy(); } }); describe('OneDrive backend', () => { it('has token field (required)', () => { const f = BACKEND_REGISTRY.onedrive.fields.find(f => f.key === 'token'); expect(f).toBeDefined(); expect(f!.required).toBe(true); expect(f!.inputType).toBe('password'); }); it('has drive_id field (required)', () => { const f = BACKEND_REGISTRY.onedrive.fields.find(f => f.key === 'drive_id'); expect(f).toBeDefined(); expect(f!.required).toBe(true); }); it('has drive_type field as select', () => { const f = BACKEND_REGISTRY.onedrive.fields.find(f => f.key === 'drive_type'); expect(f).toBeDefined(); expect(f!.inputType).toBe('select'); expect(f!.options).toBeDefined(); }); }); describe('SFTP backend', () => { it('has host field (required)', () => { const f = BACKEND_REGISTRY.sftp.fields.find(f => f.key === 'host'); expect(f).toBeDefined(); expect(f!.required).toBe(true); }); it('has user field (required)', () => { const f = BACKEND_REGISTRY.sftp.fields.find(f => f.key === 'user'); expect(f).toBeDefined(); expect(f!.required).toBe(true); }); it('has pass field (optional — SftpAuthToggle handles display)', () => { const f = BACKEND_REGISTRY.sftp.fields.find(f => f.key === 'pass'); expect(f).toBeDefined(); expect(f!.required).toBe(false); }); it('has key_pem field (optional — SftpAuthToggle handles display)', () => { const f = BACKEND_REGISTRY.sftp.fields.find(f => f.key === 'key_pem'); expect(f).toBeDefined(); expect(f!.required).toBe(false); }); }); describe('Google Cloud Storage backend', () => { it('has project_number field (required)', () => { const f = BACKEND_REGISTRY.gcs.fields.find(f => f.key === 'project_number'); expect(f).toBeDefined(); expect(f!.required).toBe(true); }); it('has service_account_credentials field (required, password)', () => { const f = BACKEND_REGISTRY.gcs.fields.find(f => f.key === 'service_account_credentials'); expect(f).toBeDefined(); expect(f!.required).toBe(true); expect(f!.inputType).toBe('password'); }); }); describe('Backblaze B2 backend', () => { it('has account field (required) — applicationKeyId', () => { const f = BACKEND_REGISTRY.b2.fields.find(f => f.key === 'account'); expect(f).toBeDefined(); expect(f!.required).toBe(true); }); it('has key field (required) — application key secret', () => { const f = BACKEND_REGISTRY.b2.fields.find(f => f.key === 'key'); expect(f).toBeDefined(); expect(f!.required).toBe(true); expect(f!.inputType).toBe('password'); }); }); });