11import { ApiService } from '@mixcore/api' ;
22import { MixDatabaseDataRestPortalService } from '../src/mix-database-data-rest-portal-service' ;
3+ import { Blob } from 'node:buffer' ;
34
45describe ( 'MixDatabaseDataRestPortalService' , ( ) => {
56 let api : ApiService ;
@@ -63,7 +64,9 @@ describe('MixDatabaseDataRestPortalService', () => {
6364 } ) ;
6465
6566 it ( 'should return error if no mixDatabaseName for import' , async ( ) => {
66- const result = await portalService . import ( '' , new File ( [ '' ] , 'test.txt' ) ) ;
67+ const fakeFile = new Blob ( [ '' ] , { type : 'text/plain' } ) as unknown as File ;
68+ Object . defineProperty ( fakeFile , 'name' , { value : 'test.txt' } ) ;
69+ const result = await portalService . import ( '' , fakeFile ) ;
6770 expect ( result . isSucceed ) . toBe ( false ) ;
6871 expect ( result . errors ) . toContain ( 'Missing mixDatabaseName' ) ;
6972 } ) ;
@@ -75,7 +78,8 @@ describe('MixDatabaseDataRestPortalService', () => {
7578 } ) ;
7679
7780 it ( 'should call import' , async ( ) => {
78- const fakeFile = new File ( [ 'test' ] , 'test.txt' , { type : 'text/plain' } ) ;
81+ const fakeFile = new Blob ( [ 'test' ] , { type : 'text/plain' } ) as unknown as File ;
82+ Object . defineProperty ( fakeFile , 'name' , { value : 'test.txt' } ) ;
7983 globalThis . fetch = jest . fn ( ) . mockResolvedValue ( { ok : true , json : async ( ) => ( { imported : true } ) } ) ;
8084 const result = await portalService . import ( 'testdb' , fakeFile ) ;
8185 expect ( result . data ) . toEqual ( { imported : true } ) ;
0 commit comments