@@ -8,9 +8,9 @@ jest.mock('../../src/index');
88( global as any ) . fetch = jest . fn ( ) ;
99
1010// Mock fs and path modules
11- jest . mock ( 'node:fs' , ( ) => ( {
12- statSync : jest . fn ( ) ,
13- readFileSync : jest . fn ( ) ,
11+ jest . mock ( 'node:fs/promises ' , ( ) => ( {
12+ stat : jest . fn ( ) ,
13+ readFile : jest . fn ( ) ,
1414} ) ) ;
1515
1616jest . mock ( 'node:path' , ( ) => ( {
@@ -29,7 +29,7 @@ describe('StorageObject (New API)', () => {
2929
3030 beforeEach ( ( ) => {
3131 // Get mocked modules
32- mockFs = require ( 'node:fs' ) ;
32+ mockFs = require ( 'node:fs/promises ' ) ;
3333 mockPath = require ( 'node:path' ) ;
3434
3535 // Create mock client instance with proper structure
@@ -462,8 +462,8 @@ describe('StorageObject (New API)', () => {
462462
463463 it ( 'should upload a text file with auto-detected content-type' , async ( ) => {
464464 const mockFileBuffer = Buffer . from ( 'test content' ) ;
465- mockFs . statSync . mockReturnValue ( { isFile : ( ) => true } ) ;
466- mockFs . readFileSync . mockReturnValue ( mockFileBuffer ) ;
465+ mockFs . stat . mockResolvedValue ( { isFile : ( ) => true } ) ;
466+ mockFs . readFile . mockResolvedValue ( mockFileBuffer ) ;
467467
468468 const mockObjectData = { id : 'file-123' , upload_url : 'https://upload.example.com/file' } ;
469469 const mockObjectInfo = { ...mockObjectData , name : 'test.txt' , state : 'UPLOADING' } ;
@@ -485,15 +485,15 @@ describe('StorageObject (New API)', () => {
485485 { name : 'test.txt' , content_type : 'text' , metadata : null } ,
486486 undefined ,
487487 ) ;
488- expect ( mockFs . readFileSync ) . toHaveBeenCalledWith ( './test.txt' ) ;
488+ expect ( mockFs . readFile ) . toHaveBeenCalledWith ( './test.txt' ) ;
489489 expect ( result ) . toBeInstanceOf ( StorageObject ) ;
490490 expect ( result . id ) . toBe ( 'file-123' ) ;
491491 } ) ;
492492
493493 it ( 'should upload a file with explicit content-type and custom name' , async ( ) => {
494494 const mockFileBuffer = Buffer . from ( 'binary content' ) ;
495- mockFs . statSync . mockReturnValue ( { isFile : ( ) => true } ) ;
496- mockFs . readFileSync . mockReturnValue ( mockFileBuffer ) ;
495+ mockFs . stat . mockResolvedValue ( { isFile : ( ) => true } ) ;
496+ mockFs . readFile . mockResolvedValue ( mockFileBuffer ) ;
497497
498498 const mockObjectData = { id : 'file-456' , upload_url : 'https://upload.example.com/file' } ;
499499 const mockObjectInfo = { ...mockObjectData , name : 'custom.bin' , state : 'UPLOADING' } ;
@@ -535,9 +535,7 @@ describe('StorageObject (New API)', () => {
535535 } ) ;
536536
537537 it ( 'should handle file read errors gracefully' , async ( ) => {
538- mockFs . statSync . mockImplementation ( ( ) => {
539- throw new Error ( 'File not found' ) ;
540- } ) ;
538+ mockFs . stat . mockRejectedValue ( new Error ( 'File not found' ) ) ;
541539
542540 await expect (
543541 StorageObject . uploadFromFile ( mockClient , './nonexistent.txt' , 'nonexistent.txt' , { } ) ,
@@ -546,8 +544,8 @@ describe('StorageObject (New API)', () => {
546544
547545 it ( 'should handle upload failures gracefully' , async ( ) => {
548546 const mockFileBuffer = Buffer . from ( 'test content' ) ;
549- mockFs . statSync . mockReturnValue ( { isFile : ( ) => true } ) ;
550- mockFs . readFileSync . mockReturnValue ( mockFileBuffer ) ;
547+ mockFs . stat . mockResolvedValue ( { isFile : ( ) => true } ) ;
548+ mockFs . readFile . mockResolvedValue ( mockFileBuffer ) ;
551549
552550 const mockObjectData = { id : 'file-789' , upload_url : 'https://upload.example.com/file' } ;
553551 const mockObjectInfo = { ...mockObjectData , name : 'test.txt' , state : 'UPLOADING' } ;
@@ -568,8 +566,8 @@ describe('StorageObject (New API)', () => {
568566
569567 it ( 'should upload an archive file with auto-detected content-type' , async ( ) => {
570568 const mockArchiveBuffer = Buffer . from ( 'compressed archive content' ) ;
571- mockFs . statSync . mockReturnValue ( { isFile : ( ) => true } ) ;
572- mockFs . readFileSync . mockReturnValue ( mockArchiveBuffer ) ;
569+ mockFs . stat . mockResolvedValue ( { isFile : ( ) => true } ) ;
570+ mockFs . readFile . mockResolvedValue ( mockArchiveBuffer ) ;
573571
574572 const mockObjectData = { id : 'archive-123' , upload_url : 'https://upload.example.com/archive' } ;
575573 const mockObjectInfo = { ...mockObjectData , name : 'project.tar.gz' , state : 'UPLOADING' } ;
@@ -595,7 +593,7 @@ describe('StorageObject (New API)', () => {
595593 { name : 'test-archive.tar.gz' , content_type : 'tgz' , metadata : null } ,
596594 undefined ,
597595 ) ;
598- expect ( mockFs . readFileSync ) . toHaveBeenCalledWith ( './files/test-archive.tar.gz' ) ;
596+ expect ( mockFs . readFile ) . toHaveBeenCalledWith ( './files/test-archive.tar.gz' ) ;
599597 expect ( result ) . toBeInstanceOf ( StorageObject ) ;
600598 expect ( result . id ) . toBe ( 'archive-123' ) ;
601599 } ) ;
0 commit comments