Skip to content

Commit 2a357f5

Browse files
committed
feat: Update import tests to use Blob for file creation
1 parent bc99852 commit 2a357f5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/database/tests/mix-database-data-rest-portal-service.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ApiService } from '@mixcore/api';
22
import { MixDatabaseDataRestPortalService } from '../src/mix-database-data-rest-portal-service';
3+
import { Blob } from 'node:buffer';
34

45
describe('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

Comments
 (0)