You need to sign in to do that
Don't have an account?
Mukesh Kumar 470
please help me how to write test case positive and negative scenario for below code
@istest
public class FileUpload_ctrlTest {
@isTest
public static void Unittest() {
Account Acc = new Account ();
Acc.Name = 'Test Account';
//Fill All Required fields
insert Acc;
system.debug('account name'+Acc.name);
Id parentId = Acc.Id;
String fileName = 'TestFile';
String base64Data = EncodingUtil.urlDecode('Test base64Data For testing', 'UTF-8');
String contentType = 'jpg';
String fileDescription = 'Testing File';
FileUpload_ctrl.saveFile(parentId,fileName,base64Data,contentType,fileDescription );
public class FileUpload_ctrlTest {
@isTest
public static void Unittest() {
Account Acc = new Account ();
Acc.Name = 'Test Account';
//Fill All Required fields
insert Acc;
system.debug('account name'+Acc.name);
Id parentId = Acc.Id;
String fileName = 'TestFile';
String base64Data = EncodingUtil.urlDecode('Test base64Data For testing', 'UTF-8');
String contentType = 'jpg';
String fileDescription = 'Testing File';
FileUpload_ctrl.saveFile(parentId,fileName,base64Data,contentType,fileDescription );
}
I hope you only attached the code for test class. Your question dont have main class logic. Can you add the main class so experts cann answer it.
Thanks,
main class is below
public without sharing class FileUpload_ctrl {
@AuraEnabled
public static Id saveFile(Id parentId, String fileName, String base64Data, String contentType, String fileDescription ) {
ContentVersion contentToInsert = new ContentVersion();
contentToInsert.Title = fileDescription + ' - ' + fileName;
contentToInsert.VersionData = EncodingUtil.base64Decode(EncodingUtil.urlDecode(base64Data, 'UTF-8'));
contentToInsert.PathOnClient = '/' + fileName ;
contentToInsert.Description = fileDescription;
contentToInsert.IsMajorVersion = false;
insert contentToInsert;
contentToInsert = [select id, ContentDocumentId from ContentVersion WHERE Id =: contentToInsert.Id];
ContentDocumentLink cl = new ContentDocumentLink();
cl.ContentDocumentId = contentToInsert.ContentDocumentId;
cl.LinkedEntityId = parentId;
cl.ShareType = 'V';
cl.Visibility = 'AllUsers';
insert cl;
return contentToInsert.id;
}
}