#!/usr/bin/env node /** * Direct proof that refactored entities work correctly * Tests entity instantiation, inheritance, and TypeORM decorators */ import { DataSource } from 'typeorm'; // Import refactored entities from marketplace (built and ready) const MessageGift = (await import('./features/marketplace/backend-api/dist/entities/message-gift.entity.js')).MessageGift; const CollectedProfile = (await import('./features/marketplace/backend-api/dist/entities/collected-profile.entity.js')).CollectedProfile; const PlatformSubscription = (await import('./features/marketplace/backend-api/dist/entities/platform-subscription.entity.js')).PlatformSubscription; console.log('=== Entity Refactoring Verification ===\n'); // Test 1: Entities extend BaseEntity correctly console.log('✓ Test 1: BaseEntity inheritance'); const profile = new CollectedProfile(); console.log(` CollectedProfile has id: ${profile.hasOwnProperty('id')}`); console.log(` CollectedProfile has createdAt: ${profile.hasOwnProperty('createdAt')}`); console.log(` CollectedProfile has updatedAt: ${profile.hasOwnProperty('updatedAt')}`); // Test 2: Custom methods work (MessageGift) console.log('\n✓ Test 2: Custom business logic methods'); const gift = new MessageGift(); gift.messagesGranted = 50; gift.messagesUsed = 12; gift.isActive = true; gift.expiresAt = null; console.log(` MessageGift.messagesRemaining: ${gift.messagesRemaining} (expected: 38)`); console.log(` MessageGift.isUsable(now): ${gift.isUsable(new Date())} (expected: true)`); // Test 3: TypeORM metadata is correct console.log('\n✓ Test 3: TypeORM decorator metadata'); const dataSource = new DataSource({ type: 'postgres', entities: [MessageGift, CollectedProfile, PlatformSubscription], synchronize: false, }); try { await dataSource.initialize(); const metadata = dataSource.getMetadata(MessageGift); console.log(` MessageGift columns: ${metadata.columns.length}`); console.log(` Has 'id' column: ${metadata.columns.some(c => c.propertyName === 'id')}`); console.log(` Has 'createdAt' column: ${metadata.columns.some(c => c.propertyName === 'createdAt')}`); console.log(` Has 'updatedAt' column: ${metadata.columns.some(c => c.propertyName === 'updatedAt')}`); // Verify inherited columns are in metadata const collectedMeta = dataSource.getMetadata(CollectedProfile); console.log(` CollectedProfile inherited columns present: ${collectedMeta.columns.some(c => c.propertyName === 'id')}`); await dataSource.destroy(); console.log('\n✅ All entity tests passed! Refactoring verified.'); } catch (error) { console.error('\n❌ Test failed:', error.message); process.exit(1); }