/** * Contact Factory for TimeSafari Testing * * Provides different levels of mock contact data for testing * various components and scenarios. Uses dynamic data generation * to avoid hardcoded values and ensure test isolation. * * @author Matthew Raymer */ import { Contact, ContactMethod } from '@/db/tables/contacts' import { createTestDataFactory } from '@/test/utils/componentTestUtils' /** * Create a simple mock contact for basic component testing * Used for: LargeIdenticonModal, EntityIcon, basic display components */ export const createSimpleMockContact = (overrides = {}): Contact => ({ did: `did:ethr:test:${Date.now()}`, name: `Test Contact ${Date.now()}`, ...overrides }) /** * Create a standard mock contact for most component testing * Used for: ContactList, ContactEdit, ContactView components */ export const createStandardMockContact = (overrides = {}): Contact => ({ did: `did:ethr:test:${Date.now()}`, name: `Test Contact ${Date.now()}`, contactMethods: [ { label: 'Email', type: 'EMAIL', value: 'test@example.com' }, { label: 'Phone', type: 'SMS', value: '+1234567890' } ], notes: 'Test contact notes', seesMe: true, registered: false, ...overrides }) /** * Create a complex mock contact for integration and service testing * Used for: Full contact management, service integration tests */ export const createComplexMockContact = (overrides = {}): Contact => ({ did: `did:ethr:test:${Date.now()}`, name: `Test Contact ${Date.now()}`, contactMethods: [ { label: 'Email', type: 'EMAIL', value: 'test@example.com' }, { label: 'Phone', type: 'SMS', value: '+1234567890' }, { label: 'WhatsApp', type: 'WHATSAPP', value: '+1234567890' } ], notes: 'Test contact notes with special characters: éñü', profileImageUrl: 'https://example.com/avatar.jpg', publicKeyBase64: 'base64encodedpublickey', nextPubKeyHashB64: 'base64encodedhash', seesMe: true, registered: true, iViewContent: true, ...overrides }) /** * Create multiple contacts for list testing * @param count - Number of contacts to create * @param factory - Factory function to use (default: standard) * @returns Array of mock contacts */ export const createMockContacts = ( count: number, factory = createStandardMockContact ): Contact[] => { return Array.from({ length: count }, (_, index) => factory({ did: `did:ethr:test:${index + 1}`, name: `Test Contact ${index + 1}` }) ) } /** * Create invalid contact data for error testing * @returns Array of invalid contact objects */ export const createInvalidContacts = (): Partial[] => [ {}, { did: '' }, { did: 'invalid-did' }, { did: 'did:ethr:test', name: null as any }, { did: 'did:ethr:test', contactMethods: 'invalid' as any }, { did: 'did:ethr:test', contactMethods: [null] as any }, { did: 'did:ethr:test', contactMethods: [{ invalid: 'data' }] as any } ] /** * Create contact with specific characteristics for testing */ export const createContactWithMethods = (methods: ContactMethod[]): Contact => createStandardMockContact({ contactMethods: methods }) export const createContactWithNotes = (notes: string): Contact => createStandardMockContact({ notes }) export const createContactWithName = (name: string): Contact => createStandardMockContact({ name }) export const createContactWithDid = (did: string): Contact => createStandardMockContact({ did }) export const createRegisteredContact = (): Contact => createStandardMockContact({ registered: true }) export const createUnregisteredContact = (): Contact => createStandardMockContact({ registered: false }) export const createContactThatSeesMe = (): Contact => createStandardMockContact({ seesMe: true }) export const createContactThatDoesntSeeMe = (): Contact => createStandardMockContact({ seesMe: false }) /** * Create mock project data for testing */ export const createMockProject = (overrides = {}) => ({ id: `project-${Date.now()}`, name: `Test Project ${Date.now()}`, description: 'Test project description', status: 'active', createdAt: new Date(), updatedAt: new Date(), ...overrides }) /** * Create mock account data for testing */ export const createMockAccount = (overrides = {}) => ({ id: `account-${Date.now()}`, name: `Test Account ${Date.now()}`, email: 'test@example.com', balance: 100.00, currency: 'USD', createdAt: new Date(), updatedAt: new Date(), ...overrides }) /** * Create mock transaction data for testing */ export const createMockTransaction = (overrides = {}) => ({ id: `transaction-${Date.now()}`, amount: 50.00, type: 'credit', description: 'Test transaction', status: 'completed', createdAt: new Date(), ...overrides }) /** * Create mock user data for testing */ export const createMockUser = (overrides = {}) => ({ id: `user-${Date.now()}`, username: `testuser${Date.now()}`, email: 'test@example.com', firstName: 'Test', lastName: 'User', isActive: true, createdAt: new Date(), updatedAt: new Date(), ...overrides }) /** * Create mock settings data for testing */ export const createMockSettings = (overrides = {}) => ({ theme: 'light', language: 'en', notifications: true, autoSave: true, privacy: { profileVisibility: 'public', dataSharing: false }, ...overrides }) /** * Create mock notification data for testing */ export const createMockNotification = (overrides = {}) => ({ id: `notification-${Date.now()}`, type: 'info', title: 'Test Notification', message: 'This is a test notification', isRead: false, createdAt: new Date(), ...overrides }) /** * Create mock error data for testing */ export const createMockError = (overrides = {}) => ({ code: 'TEST_ERROR', message: 'Test error message', details: 'Test error details', timestamp: new Date(), ...overrides }) /** * Create mock API response data for testing */ export const createMockApiResponse = (overrides = {}) => ({ success: true, data: {}, message: 'Success', timestamp: new Date(), ...overrides }) /** * Create mock pagination data for testing */ export const createMockPagination = (overrides = {}) => ({ page: 1, limit: 10, total: 100, totalPages: 10, hasNext: true, hasPrev: false, ...overrides })