101 lines
3.3 KiB
OpenEdge ABL
101 lines
3.3 KiB
OpenEdge ABL
@IsTest
|
|
public with sharing class BoxFeatureTest {
|
|
|
|
/*
|
|
* Mock - Box List Files Success
|
|
*/
|
|
private class BoxListFilesSuccessMock implements HttpCalloutMock {
|
|
public HTTPResponse respond(HTTPRequest req) {
|
|
|
|
HttpResponse res = new HttpResponse();
|
|
res.setStatusCode(200);
|
|
res.setHeader('Content-Type', 'application/json');
|
|
|
|
res.setBody('{' +
|
|
'"entries":[' +
|
|
'{' +
|
|
'"id":"123",' +
|
|
'"name":"Test Folder",' +
|
|
'"type":"folder",' +
|
|
'"created_at":"2024-01-01T10:00:00Z",' +
|
|
'"created_by":{"name":"Test User"}' +
|
|
'},' +
|
|
'{' +
|
|
'"id":"456",' +
|
|
'"name":"Test File.txt",' +
|
|
'"type":"file",' +
|
|
'"created_at":"2024-01-02T10:00:00Z",' +
|
|
'"created_by":{"name":"Another User"}' +
|
|
'}' +
|
|
']' +
|
|
'}');
|
|
|
|
return res;
|
|
}
|
|
}
|
|
|
|
// Success Test
|
|
@IsTest
|
|
static void testListFilesSuccess() {
|
|
|
|
Test.setMock(HttpCalloutMock.class, new BoxListFilesSuccessMock());
|
|
|
|
Map<String, Object> params = new Map<String, Object>{
|
|
'isServiceMode' => false,
|
|
'myDrive' => true,
|
|
'isRootFolder' => true,
|
|
'folderId' => '',
|
|
'accessToken' => 'dummyAccessToken',
|
|
'level' => 'root'
|
|
};
|
|
|
|
BoxFeature service = new BoxFeature();
|
|
|
|
Test.startTest();
|
|
OperationResult result = service.listFiles(params);
|
|
Test.stopTest();
|
|
|
|
}
|
|
|
|
@IsTest
|
|
static void testLinkFilesSuccess() {
|
|
|
|
// Create parent record
|
|
Account acc = new Account(Name = 'Test Account');
|
|
insert acc;
|
|
|
|
// ⚠ IMPORTANT:
|
|
// Replace 'Read' with a VALID picklist value from your org
|
|
HIC_FilesME__Linked_Folder__c folder = new HIC_FilesME__Linked_Folder__c(
|
|
Name = 'Test Folder',
|
|
HIC_FilesME__Linked_Record__c = acc.Id,
|
|
HIC_FilesME__External_Folder_ID__c = 'EXT123',
|
|
HIC_FilesME__Folder_Name__c = 'Demo Folder',
|
|
HIC_FilesME__Folder_URL__c = 'https://example.com',
|
|
HIC_FilesME__Storage_Provider__c = 'awss3',
|
|
HIC_FilesME__Access_Level__c = 'Public',
|
|
HIC_FilesME__Is_Active__c = true
|
|
);
|
|
insert folder;
|
|
|
|
AWSS3Feature service = new AWSS3Feature();
|
|
|
|
Test.startTest();
|
|
OperationResult result = service.linkFiles(folder.Id);
|
|
Test.stopTest();
|
|
|
|
System.assertNotEquals(null, result);
|
|
|
|
List<Object> data = (List<Object>) result.data;
|
|
System.assertEquals(1, data.size());
|
|
Map<String, String> folderData = (Map<String, String>) data[0];
|
|
|
|
System.assertEquals('EXT123', folderData.get('id'));
|
|
System.assertEquals('Demo Folder', folderData.get('name'));
|
|
// System.assertEquals('AwsS3', folderData.get('externalStorageType'));
|
|
System.assertEquals('Public', folderData.get('accessLevel'));
|
|
System.assertEquals('https://example.com', folderData.get('url'));
|
|
}
|
|
|
|
|
|
} |