@@ -961,6 +961,123 @@ describe('DriveService', () => {
961961 } ) ;
962962 } ) ;
963963
964+ describe ( 'trashFile' , ( ) => {
965+ it ( 'should trash a file by ID' , async ( ) => {
966+ mockDriveAPI . files . update . mockResolvedValue ( {
967+ data : { id : 'file-id-123' , name : 'My File.pdf' } ,
968+ } ) ;
969+
970+ const result = await driveService . trashFile ( { fileId : 'file-id-123' } ) ;
971+
972+ expect ( mockDriveAPI . files . update ) . toHaveBeenCalledWith ( {
973+ fileId : 'file-id-123' ,
974+ requestBody : { trashed : true } ,
975+ fields : 'id, name' ,
976+ supportsAllDrives : true ,
977+ } ) ;
978+ expect ( JSON . parse ( result . content [ 0 ] . text ) ) . toEqual ( {
979+ id : 'file-id-123' ,
980+ name : 'My File.pdf' ,
981+ trashed : true ,
982+ } ) ;
983+ } ) ;
984+
985+ it ( 'should extract ID from a Drive URL' , async ( ) => {
986+ mockDriveAPI . files . update . mockResolvedValue ( {
987+ data : { id : 'file-url-id' , name : 'URL File.pdf' } ,
988+ } ) ;
989+
990+ const result = await driveService . trashFile ( {
991+ fileId : 'https://drive.google.com/file/d/file-url-id/view' ,
992+ } ) ;
993+
994+ expect ( mockDriveAPI . files . update ) . toHaveBeenCalledWith ( {
995+ fileId : 'file-url-id' ,
996+ requestBody : { trashed : true } ,
997+ fields : 'id, name' ,
998+ supportsAllDrives : true ,
999+ } ) ;
1000+ expect ( JSON . parse ( result . content [ 0 ] . text ) ) . toEqual ( {
1001+ id : 'file-url-id' ,
1002+ name : 'URL File.pdf' ,
1003+ trashed : true ,
1004+ } ) ;
1005+ } ) ;
1006+
1007+ it ( 'should handle API errors gracefully' , async ( ) => {
1008+ mockDriveAPI . files . update . mockRejectedValue (
1009+ new Error ( 'Permission denied' ) ,
1010+ ) ;
1011+
1012+ const result = await driveService . trashFile ( { fileId : 'file-id-123' } ) ;
1013+
1014+ expect ( JSON . parse ( result . content [ 0 ] . text ) ) . toEqual ( {
1015+ error : 'Permission denied' ,
1016+ } ) ;
1017+ } ) ;
1018+ } ) ;
1019+
1020+ describe ( 'renameFile' , ( ) => {
1021+ it ( 'should rename a file by ID' , async ( ) => {
1022+ mockDriveAPI . files . update . mockResolvedValue ( {
1023+ data : { id : 'file-id-123' , name : 'New Name' } ,
1024+ } ) ;
1025+
1026+ const result = await driveService . renameFile ( {
1027+ fileId : 'file-id-123' ,
1028+ newName : 'New Name' ,
1029+ } ) ;
1030+
1031+ expect ( mockDriveAPI . files . update ) . toHaveBeenCalledWith ( {
1032+ fileId : 'file-id-123' ,
1033+ requestBody : { name : 'New Name' } ,
1034+ fields : 'id, name' ,
1035+ supportsAllDrives : true ,
1036+ } ) ;
1037+
1038+ expect ( JSON . parse ( result . content [ 0 ] . text ) ) . toEqual ( {
1039+ id : 'file-id-123' ,
1040+ name : 'New Name' ,
1041+ } ) ;
1042+ } ) ;
1043+
1044+ it ( 'should extract ID from a Drive URL' , async ( ) => {
1045+ mockDriveAPI . files . update . mockResolvedValue ( {
1046+ data : { id : 'doc-url-id' , name : 'Renamed Doc' } ,
1047+ } ) ;
1048+
1049+ const result = await driveService . renameFile ( {
1050+ fileId : 'https://docs.google.com/document/d/doc-url-id/edit' ,
1051+ newName : 'Renamed Doc' ,
1052+ } ) ;
1053+
1054+ expect ( mockDriveAPI . files . update ) . toHaveBeenCalledWith ( {
1055+ fileId : 'doc-url-id' ,
1056+ requestBody : { name : 'Renamed Doc' } ,
1057+ fields : 'id, name' ,
1058+ supportsAllDrives : true ,
1059+ } ) ;
1060+
1061+ expect ( JSON . parse ( result . content [ 0 ] . text ) ) . toEqual ( {
1062+ id : 'doc-url-id' ,
1063+ name : 'Renamed Doc' ,
1064+ } ) ;
1065+ } ) ;
1066+
1067+ it ( 'should handle API errors gracefully' , async ( ) => {
1068+ mockDriveAPI . files . update . mockRejectedValue ( new Error ( 'File not found' ) ) ;
1069+
1070+ const result = await driveService . renameFile ( {
1071+ fileId : 'file-id-123' ,
1072+ newName : 'New Name' ,
1073+ } ) ;
1074+
1075+ expect ( JSON . parse ( result . content [ 0 ] . text ) ) . toEqual ( {
1076+ error : 'File not found' ,
1077+ } ) ;
1078+ } ) ;
1079+ } ) ;
1080+
9641081 describe ( 'Shared Drive Support' , ( ) => {
9651082 it ( 'findFolder should include shared drive flags' , async ( ) => {
9661083 mockDriveAPI . files . list . mockResolvedValue ( { data : { files : [ ] } } ) ;
0 commit comments