1+ import { jsonResponse } from '@sim/testing'
2+ import {
3+ fileUtilsServerMock ,
4+ fileUtilsServerMockFns ,
5+ } from '@sim/testing/mocks/file-utils-server.mock'
6+ import {
7+ inputValidationMock ,
8+ inputValidationMockFns ,
9+ } from '@sim/testing/mocks/input-validation.mock'
110import { beforeEach , describe , expect , it , vi } from 'vitest'
211
3- const { mockResolveFileInputToUrl, mockSubmitExtendParse } = vi . hoisted ( ( ) => ( {
4- mockResolveFileInputToUrl : vi . fn ( ) ,
5- mockSubmitExtendParse : vi . fn ( ) ,
6- } ) )
12+ vi . mock ( '@/lib/uploads/utils/file.server' , ( ) => fileUtilsServerMock )
13+ vi . mock ( '@/lib/core/security/input-validation.server' , ( ) => inputValidationMock )
714
8- vi . mock ( '@/lib/uploads/utils/file.server' , ( ) => ( {
9- resolveFileInputToUrl : mockResolveFileInputToUrl ,
10- } ) )
11- vi . mock ( '@/lib/internal/extend/client' , ( ) => ( {
12- submitExtendParse : mockSubmitExtendParse ,
13- } ) )
15+ const { mockResolveFileInputToUrl } = fileUtilsServerMockFns
16+ const { mockSecureFetchWithPinnedIP, mockValidateUrlWithDNS } = inputValidationMockFns
1417
1518import { ExtendOperationError } from '@/lib/internal/extend/errors'
1619import { executeExtendParse } from '@/lib/internal/extend/operations'
@@ -21,16 +24,19 @@ const input = { apiKey: 'key', filePath: 'https://files.example.com/doc.pdf' }
2124describe ( 'executeExtendParse' , ( ) => {
2225 beforeEach ( ( ) => {
2326 mockResolveFileInputToUrl . mockResolvedValue ( { fileUrl : 'https://files.example.com/doc.pdf' } )
27+ mockValidateUrlWithDNS . mockResolvedValue ( { isValid : true , resolvedIP : '203.0.113.1' } )
2428 } )
2529
2630 it ( 'reads the page count and credits from the parser run metrics and usage' , async ( ) => {
27- mockSubmitExtendParse . mockResolvedValue ( {
28- id : 'parser_run_1' ,
29- status : 'PROCESSED' ,
30- chunks : [ ] ,
31- metrics : { processingTimeMs : 900 , pageCount : 4 } ,
32- usage : { credits : 8 } ,
33- } )
31+ mockSecureFetchWithPinnedIP . mockResolvedValue (
32+ jsonResponse ( {
33+ id : 'parser_run_1' ,
34+ status : 'PROCESSED' ,
35+ chunks : [ ] ,
36+ metrics : { processingTimeMs : 900 , pageCount : 4 } ,
37+ usage : { credits : 8 } ,
38+ } )
39+ )
3440
3541 const result = await executeExtendParse ( input , context )
3642
@@ -39,12 +45,14 @@ describe('executeExtendParse', () => {
3945 } )
4046
4147 it ( 'fails with the failure reason when Extend could not parse the file' , async ( ) => {
42- mockSubmitExtendParse . mockResolvedValue ( {
43- id : 'parser_run_1' ,
44- status : 'FAILED' ,
45- failureReason : 'CORRUPT_FILE' ,
46- chunks : [ ] ,
47- } )
48+ mockSecureFetchWithPinnedIP . mockResolvedValue (
49+ jsonResponse ( {
50+ id : 'parser_run_1' ,
51+ status : 'FAILED' ,
52+ failureReason : 'CORRUPT_FILE' ,
53+ chunks : [ ] ,
54+ } )
55+ )
4856
4957 await expect ( executeExtendParse ( input , context ) ) . rejects . toEqual (
5058 new ExtendOperationError ( 422 , {
0 commit comments