@@ -10,6 +10,7 @@ import {
1010 FolderAncestorWorkspace ,
1111 MoveFolderPayload ,
1212 MoveFolderResponse ,
13+ SearchResultData ,
1314 UpdateFilePayload ,
1415} from '../../../src/drive/storage/types' ;
1516import { ApiSecurity , AppDetails } from '../../../src/shared' ;
@@ -1027,6 +1028,72 @@ describe('# storage service tests', () => {
10271028 } ) ;
10281029 } ) ;
10291030 } ) ;
1031+
1032+ describe ( '-> global search' , ( ) => {
1033+ const emptySearchResponse : SearchResultData = { data : [ ] as unknown as SearchResultData [ 'data' ] } ;
1034+
1035+ it ( 'Should post to the personal fuzzy endpoint with an empty body, when no options are passed' , async ( ) => {
1036+ const { client, headers } = clientAndHeaders ( { } ) ;
1037+ const postCancellableStub = vi . spyOn ( HttpClient . prototype , 'postCancellable' ) . mockReturnValue ( {
1038+ promise : Promise . resolve ( emptySearchResponse ) ,
1039+ requestCanceler : { cancel : ( ) => null } ,
1040+ } ) ;
1041+
1042+ const [ promise ] = client . getGlobalSearchItems ( 'report' ) ;
1043+ await promise ;
1044+
1045+ expect ( postCancellableStub ) . toHaveBeenCalledWith ( 'fuzzy/report' , { } , headers ) ;
1046+ } ) ;
1047+
1048+ it ( 'Should post to the workspace fuzzy endpoint, when a workspaceId is passed' , async ( ) => {
1049+ const workspaceId = 'workspace-id' ;
1050+ const { client, headers } = clientAndHeaders ( { } ) ;
1051+ const postCancellableStub = vi . spyOn ( HttpClient . prototype , 'postCancellable' ) . mockReturnValue ( {
1052+ promise : Promise . resolve ( emptySearchResponse ) ,
1053+ requestCanceler : { cancel : ( ) => null } ,
1054+ } ) ;
1055+
1056+ const [ promise ] = client . getGlobalSearchItems ( 'report' , workspaceId ) ;
1057+ await promise ;
1058+
1059+ expect ( postCancellableStub ) . toHaveBeenCalledWith ( `workspaces/${ workspaceId } /fuzzy/report` , { } , headers ) ;
1060+ } ) ;
1061+
1062+ it ( 'Should keep supporting a numeric offset as third argument' , async ( ) => {
1063+ const { client, headers } = clientAndHeaders ( { } ) ;
1064+ const postCancellableStub = vi . spyOn ( HttpClient . prototype , 'postCancellable' ) . mockReturnValue ( {
1065+ promise : Promise . resolve ( emptySearchResponse ) ,
1066+ requestCanceler : { cancel : ( ) => null } ,
1067+ } ) ;
1068+
1069+ const [ promise ] = client . getGlobalSearchItems ( 'report' , undefined , 10 ) ;
1070+ await promise ;
1071+
1072+ expect ( postCancellableStub ) . toHaveBeenCalledWith ( 'fuzzy/report' , { offset : 10 } , headers ) ;
1073+ } ) ;
1074+
1075+ it ( 'Should send all search filters in the request body, when options are passed' , async ( ) => {
1076+ const { client, headers } = clientAndHeaders ( { } ) ;
1077+ const postCancellableStub = vi . spyOn ( HttpClient . prototype , 'postCancellable' ) . mockReturnValue ( {
1078+ promise : Promise . resolve ( emptySearchResponse ) ,
1079+ requestCanceler : { cancel : ( ) => null } ,
1080+ } ) ;
1081+
1082+ const filters = {
1083+ offset : 0 ,
1084+ type : [ 'pdf' , 'image' ] ,
1085+ minSize : 1024 ,
1086+ maxSize : 5242880 ,
1087+ modifiedAfter : '2026-01-01T00:00:00.000Z' ,
1088+ modifiedBefore : '2026-06-30T23:59:59.999Z' ,
1089+ } ;
1090+
1091+ const [ promise ] = client . getGlobalSearchItems ( 'report' , undefined , filters ) ;
1092+ await promise ;
1093+
1094+ expect ( postCancellableStub ) . toHaveBeenCalledWith ( 'fuzzy/report' , filters , headers ) ;
1095+ } ) ;
1096+ } ) ;
10301097} ) ;
10311098
10321099function clientAndHeaders ( {
0 commit comments