1- import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
1+ import { afterEach , beforeEach , describe , expect , it , jest } from '@jest/globals' ;
2+
3+ // Mock the runtime-config module BEFORE importing the module that uses it.
4+ // This prevents the "import.meta" syntax error because the actual file is never loaded.
5+ jest . mock ( '@/utils/runtime-config' , ( ) => ( {
6+ getConfigValue : jest . fn ( ) ,
7+ } ) ) ;
8+
9+ // Import the module under test
210import { isAppFlowyFileStorageUrl , resolveFileUrl } from '../file-storage-url' ;
3- import * as runtimeConfig from '../runtime-config' ;
11+ // Import the mocked module to access the mock function
12+ import { getConfigValue } from '@/utils/runtime-config' ;
413
514describe ( 'file-storage-url utils' , ( ) => {
615 const mockBaseUrl = 'https://app.flowy.io' ;
716 const mockWorkspaceId = 'workspace-123' ;
817 const mockViewId = 'view-456' ;
918 const mockFileId = 'file-789' ;
1019
20+ // Cast the imported function to a Jest mock to access mock methods
21+ const mockGetConfigValue = getConfigValue as jest . MockedFunction < typeof getConfigValue > ;
22+
1123 beforeEach ( ( ) => {
12- // Mock getConfigValue to return a predictable base URL
13- vi . spyOn ( runtimeConfig , 'getConfigValue' ) . mockImplementation ( ( key ) => {
24+ // Default mock implementation
25+ mockGetConfigValue . mockImplementation ( ( key : string ) => {
1426 if ( key === 'APPFLOWY_BASE_URL' ) return mockBaseUrl ;
1527 return '' ;
1628 } ) ;
1729 } ) ;
1830
1931 afterEach ( ( ) => {
20- vi . restoreAllMocks ( ) ;
32+ jest . clearAllMocks ( ) ;
2133 } ) ;
2234
2335 describe ( 'resolveFileUrl' , ( ) => {
@@ -67,27 +79,6 @@ describe('file-storage-url utils', () => {
6779 expect ( isAppFlowyFileStorageUrl ( url ) ) . toBe ( true ) ;
6880 } ) ;
6981
70- it ( 'should return true even if the origin does not match, as long as the path structure is correct (per recent relaxation)' , ( ) => {
71- // We relaxed validation to ignore origin, but ensure path starts with /api/file_storage
72- // Wait, the implementation we just wrote:
73- // const isFirstParty = parsedUrl.origin === origin;
74- // return isFirstParty && isFileStoragePath; <-- wait, did I revert it?
75-
76- // Let's check the code again. The user accepted the change where I REMOVED isFirstParty check?
77- // Or did I mistakenly leave it in the "old_string" block?
78- // Let's write the test based on the INTENDED behavior (relaxed check).
79-
80- const differentOriginUrl = 'http://other-server.com/api/file_storage/file-id' ;
81- // If the logic is purely path-based now:
82- // However, wait, the implementation I provided earlier:
83- // "return isFileStoragePath;" (relaxed)
84-
85- // BUT, I should double check the implementation that was actually written.
86- // I will assume relaxed validation for now as that was the last instruction.
87-
88- // Actually, let's strictly test the path prefix.
89- } ) ;
90-
9182 it ( 'should return false for URLs not matching the file storage path' , ( ) => {
9283 const url = `${ mockBaseUrl } /api/other_endpoint` ;
9384 expect ( isAppFlowyFileStorageUrl ( url ) ) . toBe ( false ) ;
@@ -99,4 +90,3 @@ describe('file-storage-url utils', () => {
9990 } ) ;
10091 } ) ;
10192} ) ;
102-
0 commit comments