const { DocumentProcessorServiceClient } = require('@google-cloud/documentai'); const { Storage } = require('@google-cloud/storage'); // Configuration const PROJECT_ID = 'cim-summarizer'; const LOCATION = 'us'; const GCS_BUCKET_NAME = 'cim-summarizer-uploads'; const DOCUMENT_AI_OUTPUT_BUCKET_NAME = 'cim-summarizer-document-ai-output'; // Mock processor ID for testing const MOCK_PROCESSOR_ID = 'mock-processor-id-12345'; async function testIntegrationWithMock() { console.log('๐Ÿงช Testing Document AI Integration with Mock Processor...\n'); try { // Test 1: Google Cloud Storage console.log('1. Testing Google Cloud Storage...'); const storage = new Storage(); // Test bucket access const [buckets] = await storage.getBuckets(); console.log(` โœ… Found ${buckets.length} buckets`); const uploadBucket = buckets.find(b => b.name === GCS_BUCKET_NAME); const outputBucket = buckets.find(b => b.name === DOCUMENT_AI_OUTPUT_BUCKET_NAME); console.log(` ๐Ÿ“ฆ Upload bucket exists: ${!!uploadBucket}`); console.log(` ๐Ÿ“ฆ Output bucket exists: ${!!outputBucket}`); // Test 2: Document AI Client console.log('\n2. Testing Document AI Client...'); const documentAiClient = new DocumentProcessorServiceClient(); console.log(' โœ… Document AI client initialized'); // Test 3: File Upload and Processing Simulation console.log('\n3. Testing File Upload and Processing Simulation...'); if (uploadBucket) { // Create a sample CIM document const sampleCIM = ` INVESTMENT MEMORANDUM Company: Sample Tech Corp Industry: Technology Investment Size: $10M FINANCIAL SUMMARY Revenue: $5M (2023) EBITDA: $1.2M Growth Rate: 25% YoY MARKET OPPORTUNITY Total Addressable Market: $50B Market Position: Top 3 in segment Competitive Advantages: Proprietary technology, strong team INVESTMENT THESIS 1. Strong product-market fit 2. Experienced management team 3. Large market opportunity 4. Proven revenue model RISK FACTORS 1. Market competition 2. Regulatory changes 3. Technology obsolescence EXIT STRATEGY IPO or strategic acquisition within 5 years Expected return: 3-5x `; const testFileName = `test-cim-${Date.now()}.txt`; const file = uploadBucket.file(testFileName); await file.save(sampleCIM, { metadata: { contentType: 'text/plain' } }); console.log(` โœ… Uploaded sample CIM: gs://${GCS_BUCKET_NAME}/${testFileName}`); console.log(` ๐Ÿ“Š Document size: ${sampleCIM.length} characters`); // Simulate Document AI processing console.log('\n4. Simulating Document AI Processing...'); // Mock Document AI output const mockDocumentAiOutput = { text: sampleCIM, pages: [ { pageNumber: 1, width: 612, height: 792, tokens: sampleCIM.split(' ').map((word, index) => ({ text: word, confidence: 0.95, boundingBox: { x: 0, y: 0, width: 100, height: 20 } })) } ], entities: [ { type: 'COMPANY_NAME', mentionText: 'Sample Tech Corp', confidence: 0.98 }, { type: 'MONEY', mentionText: '$10M', confidence: 0.95 }, { type: 'MONEY', mentionText: '$5M', confidence: 0.95 }, { type: 'MONEY', mentionText: '$1.2M', confidence: 0.95 }, { type: 'MONEY', mentionText: '$50B', confidence: 0.95 } ], tables: [] }; console.log(` โœ… Extracted text: ${mockDocumentAiOutput.text.length} characters`); console.log(` ๐Ÿ“„ Pages: ${mockDocumentAiOutput.pages.length}`); console.log(` ๐Ÿท๏ธ Entities: ${mockDocumentAiOutput.entities.length}`); console.log(` ๐Ÿ“Š Tables: ${mockDocumentAiOutput.tables.length}`); // Test 5: Integration with Processing Pipeline console.log('\n5. Testing Integration with Processing Pipeline...'); // Simulate the processing flow const processingResult = { success: true, content: `# CIM Analysis ## Investment Summary **Company:** Sample Tech Corp **Industry:** Technology **Investment Size:** $10M ## Financial Metrics - Revenue: $5M (2023) - EBITDA: $1.2M - Growth Rate: 25% YoY ## Market Analysis - Total Addressable Market: $50B - Market Position: Top 3 in segment - Competitive Advantages: Proprietary technology, strong team ## Investment Thesis 1. Strong product-market fit 2. Experienced management team 3. Large market opportunity 4. Proven revenue model ## Risk Assessment 1. Market competition 2. Regulatory changes 3. Technology obsolescence ## Exit Strategy IPO or strategic acquisition within 5 years Expected return: 3-5x `, metadata: { processingStrategy: 'document_ai_agentic_rag', documentAiOutput: mockDocumentAiOutput, processingTime: Date.now(), fileSize: sampleCIM.length, processorId: MOCK_PROCESSOR_ID } }; console.log(` โœ… Processing completed successfully`); console.log(` ๐Ÿ“Š Output length: ${processingResult.content.length} characters`); console.log(` โฑ๏ธ Processing time: ${Date.now() - processingResult.metadata.processingTime}ms`); // Clean up test file await file.delete(); console.log(` โœ… Cleaned up test file`); // Test 6: Configuration Summary console.log('\n6. Configuration Summary...'); console.log(' โœ… Google Cloud Storage: Working'); console.log(' โœ… Document AI Client: Working'); console.log(' โœ… File Upload: Working'); console.log(' โœ… Document Processing: Simulated'); console.log(' โœ… Integration Pipeline: Ready'); console.log('\n๐ŸŽ‰ Document AI Integration Test Completed Successfully!'); console.log('\n๐Ÿ“‹ Environment Configuration:'); console.log(`GCLOUD_PROJECT_ID=${PROJECT_ID}`); console.log(`DOCUMENT_AI_LOCATION=${LOCATION}`); console.log(`DOCUMENT_AI_PROCESSOR_ID=${MOCK_PROCESSOR_ID}`); console.log(`GCS_BUCKET_NAME=${GCS_BUCKET_NAME}`); console.log(`DOCUMENT_AI_OUTPUT_BUCKET_NAME=${DOCUMENT_AI_OUTPUT_BUCKET_NAME}`); console.log('\n๐Ÿ“‹ Next Steps:'); console.log('1. Create a real Document AI processor in the console'); console.log('2. Replace MOCK_PROCESSOR_ID with the real processor ID'); console.log('3. Test with real CIM documents'); console.log('4. Integrate with your existing processing pipeline'); return processingResult; } else { console.log(' โŒ Upload bucket not found'); } } catch (error) { console.error('\nโŒ Integration test failed:', error.message); throw error; } } async function main() { try { await testIntegrationWithMock(); } catch (error) { console.error('Test failed:', error); process.exit(1); } } if (require.main === module) { main(); } module.exports = { testIntegrationWithMock };