@@ -12,6 +12,7 @@ global with sharing class qsydFileExplorerTest {
1212 private static qsyd_FileList fileItemList ;
1313 private static qsyd_Folder folderItem ;
1414 private static qsyd_FolderList folderItemList ;
15+ private static User standardUser ;
1516
1617 @TestSetup
1718 private static void setupTestData () {
@@ -27,7 +28,8 @@ global with sharing class qsydFileExplorerTest {
2728 Title = ' Penguins' ,
2829 PathOnClient = ' Penguins.jpg' ,
2930 VersionData = Blob .valueOf (SIG_B64 ),
30- IsMajorVersion = true
31+ IsMajorVersion = true ,
32+ SharingPrivacy = ' P' // set it to private on records
3133 );
3234 insert contentVersion ;
3335 List <ContentDocument > contentDocumentList = [
@@ -64,6 +66,44 @@ global with sharing class qsydFileExplorerTest {
6466 ' tags' ,
6567 contentDocumentList [0 ].ContentSize ,
6668 null );
69+
70+
71+ createStandardUser ();
72+
73+ }
74+
75+ @future
76+ private static void createStandardUser () {
77+ String uniqueUserName = ' standarduser' + DateTime .now ().getTime () + ' @file-explorer.dev' ;
78+
79+ Profile p = [
80+ SELECT Id
81+ FROM Profile
82+ WHERE Name = ' Standard User'
83+ ];
84+
85+ standardUser = new User (
86+ Alias = ' stduser' ,
87+ Email = ' standarduser@file-explorer.dev' ,
88+ EmailEncodingKey = ' UTF-8' ,
89+ LastName = ' Test' ,
90+ LanguageLocaleKey = ' en_US' ,
91+ LocaleSidKey = ' en_US' ,
92+ ProfileId = p .Id ,
93+ TimeZoneSidKey = ' Australia/Sydney' ,
94+ UserName = uniqueUserName
95+ );
96+ insert standardUser ;
97+
98+ PermissionSet ps = [
99+ SELECT Id
100+ FROM PermissionSet
101+ WHERE Name = ' File_Explorer_Permission_Set' ];
102+
103+ insert new PermissionSetAssignment (
104+ AssigneeId = standardUser .id ,
105+ PermissionSetId = ps .Id
106+ );
67107 }
68108
69109 @IsTest
@@ -150,4 +190,23 @@ global with sharing class qsydFileExplorerTest {
150190
151191 System .assertEquals (2 , canonicalFolders .size ());
152192 }
193+
194+ @IsTest
195+ private static void given_fileSetToPrivateOnRecords_when_fileRetreieved_success () {
196+ List <FileExplorerFile__c > fileExplorerFileList ;
197+
198+ setupTestData ();
199+
200+ System .runAs (standardUser ) {
201+ fileExplorerFileList = fileItemList
202+ .retrieve (a .Id )
203+ .convertToCanonical ()
204+ .getCanonicalList ();
205+
206+ // does not return any file
207+ // as only the owner can see this file
208+ // https://help.salesforce.com/s/articleView?id=sf.collab_files_make_private_on_record.htm&type=5
209+ System .assertEquals (0 , fileExplorerFileList .size ());
210+ }
211+ }
153212}
0 commit comments