Skip to content

Instantly share code, notes, and snippets.

@svierk
Last active January 24, 2024 19:17
Show Gist options
  • Save svierk/1e1c21d68b0e49b1f6abdc7a4d887025 to your computer and use it in GitHub Desktop.
Save svierk/1e1c21d68b0e49b1f6abdc7a4d887025 to your computer and use it in GitHub Desktop.
Apex Test Class for Content Document Table Component | Test Setup & Test Cases
@TestSetup
static void makeData() {
User u = new User();
u.FirstName = 'Test';
u.LastName = 'User';
u.Username = '[email protected]';
u.Alias = '123test';
u.Email = '[email protected]';
u.ProfileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator' LIMIT 1].Id;
u.TimeZoneSidKey = 'America/Chicago';
u.LocaleSidKey = 'en_US';
u.EmailEncodingKey = 'UTF-8';
u.LanguageLocaleKey = 'en_US';
insert u;
Account a = new Account();
a.Name = 'Test Account';
a.OwnerId = UserInfo.getUserId();
insert a;
}
@IsTest
public static void getDocumentsTest() {
User u = [SELECT Id FROM User WHERE Username = '[email protected]'];
System.runAs(u) {
Id accountId = [SELECT Id FROM Account WHERE Name = 'Test Account' LIMIT 1].Id;
createContentSetup(accountId);
Test.startTest();
String jsonString = ContentDocumentController.getDocuments('Test Documents', null, accountId);
Test.stopTest();
Assert.areNotEqual('', jsonString, 'Returned documents list is empty.');
}
}
@IsTest
public static void getLatestVersionTest() {
User u = [SELECT Id FROM User WHERE Username = '[email protected]'];
System.runAs(u) {
Id accountId = [SELECT Id FROM Account WHERE Name = 'Test Account' LIMIT 1].Id;
Id contentDocumentId = createContentSetup(accountId);
Test.startTest();
String version = ContentDocumentController.getLatestVersion(contentDocumentId);
Test.stopTest();
Assert.areNotEqual('', version, 'Document version does not exist.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment