@@ -2,6 +2,7 @@ import { BadRequestException } from '@nestjs/common';
2
2
import { DocumentProcessorService } from './document-processor.service' ;
3
3
import { AwsTextractService } from './aws-textract.service' ;
4
4
import { AwsBedrockService } from './aws-bedrock.service' ;
5
+ import { PerplexityService } from '../../services/perplexity.service' ;
5
6
import { describe , it , expect , vi } from 'vitest' ;
6
7
7
8
// Mock the crypto module
@@ -44,18 +45,23 @@ describe('DocumentProcessorService', () => {
44
45
} ,
45
46
} ;
46
47
48
+ const simplifiedExplanation = 'This is a simple explanation of the medical document.' ;
49
+
47
50
// Create a new test-specific instance with proper mocking
48
51
const testTextractService = { extractText : vi . fn ( ) } ;
49
52
const testBedrockService = { analyzeMedicalDocument : vi . fn ( ) } ;
53
+ const testPerplexityService = { explainMedicalText : vi . fn ( ) } ;
50
54
51
55
// Set up mocks
52
56
testTextractService . extractText . mockResolvedValue ( extractedTextResult ) ;
53
57
testBedrockService . analyzeMedicalDocument . mockResolvedValue ( medicalAnalysis ) ;
58
+ testPerplexityService . explainMedicalText . mockResolvedValue ( simplifiedExplanation ) ;
54
59
55
60
// Create a fresh service instance with our mocks
56
61
const testService = new DocumentProcessorService (
57
62
testTextractService as unknown as AwsTextractService ,
58
63
testBedrockService as unknown as AwsBedrockService ,
64
+ testPerplexityService as unknown as PerplexityService ,
59
65
) ;
60
66
61
67
// Act
@@ -67,9 +73,13 @@ describe('DocumentProcessorService', () => {
67
73
extractedTextResult . rawText ,
68
74
userId ,
69
75
) ;
76
+ expect ( testPerplexityService . explainMedicalText ) . toHaveBeenCalledWith (
77
+ extractedTextResult . rawText ,
78
+ ) ;
70
79
expect ( result ) . toEqual ( {
71
80
extractedText : extractedTextResult ,
72
81
analysis : medicalAnalysis ,
82
+ simplifiedExplanation,
73
83
processingMetadata : expect . objectContaining ( {
74
84
fileType,
75
85
fileSize : fileBuffer . length ,
@@ -86,6 +96,7 @@ describe('DocumentProcessorService', () => {
86
96
// Create test-specific service with proper mocking
87
97
const testTextractService = { extractText : vi . fn ( ) } ;
88
98
const testBedrockService = { analyzeMedicalDocument : vi . fn ( ) } ;
99
+ const testPerplexityService = { explainMedicalText : vi . fn ( ) } ;
89
100
90
101
// Make the mock reject with an error
91
102
testTextractService . extractText . mockRejectedValue ( new Error ( 'Failed to extract text' ) ) ;
@@ -94,6 +105,7 @@ describe('DocumentProcessorService', () => {
94
105
const testService = new DocumentProcessorService (
95
106
testTextractService as unknown as AwsTextractService ,
96
107
testBedrockService as unknown as AwsBedrockService ,
108
+ testPerplexityService as unknown as PerplexityService ,
97
109
) ;
98
110
99
111
// Act & Assert
@@ -115,11 +127,13 @@ describe('DocumentProcessorService', () => {
115
127
// Create test-specific service with proper mocking
116
128
const testTextractService = { extractText : vi . fn ( ) } ;
117
129
const testBedrockService = { analyzeMedicalDocument : vi . fn ( ) } ;
130
+ const testPerplexityService = { explainMedicalText : vi . fn ( ) } ;
118
131
119
132
// Create a fresh service instance with our mocks
120
133
const testService = new DocumentProcessorService (
121
134
testTextractService as unknown as AwsTextractService ,
122
135
testBedrockService as unknown as AwsBedrockService ,
136
+ testPerplexityService as unknown as PerplexityService ,
123
137
) ;
124
138
125
139
// Mock the processDocument method on our test service
@@ -142,6 +156,7 @@ describe('DocumentProcessorService', () => {
142
156
missingInformation : [ ] ,
143
157
} ,
144
158
} ,
159
+ simplifiedExplanation : 'Simple explanation for document 1' ,
145
160
processingMetadata : {
146
161
processingTimeMs : 100 ,
147
162
fileType : 'application/pdf' ,
@@ -166,6 +181,7 @@ describe('DocumentProcessorService', () => {
166
181
missingInformation : [ ] ,
167
182
} ,
168
183
} ,
184
+ simplifiedExplanation : 'Simple explanation for document 2' ,
169
185
processingMetadata : {
170
186
processingTimeMs : 100 ,
171
187
fileType : 'image/jpeg' ,
@@ -207,6 +223,7 @@ describe('DocumentProcessorService', () => {
207
223
const testService = new DocumentProcessorService (
208
224
{ } as AwsTextractService ,
209
225
{ } as AwsBedrockService ,
226
+ { } as PerplexityService ,
210
227
) ;
211
228
212
229
// Create a test implementation that checks for empty array
0 commit comments