104 lines
3.6 KiB
OpenEdge ABL
104 lines
3.6 KiB
OpenEdge ABL
/**
|
|
* This class contains unit tests for validating the behavior of Apex classes
|
|
* and triggers.
|
|
*
|
|
* Unit tests are class methods that verify whether a particular piece
|
|
* of code is working properly. Unit test methods take no arguments,
|
|
* commit no data to the database, and are flagged with the testMethod
|
|
* keyword in the method definition.
|
|
*
|
|
* All test methods in an org are executed whenever Apex code is deployed
|
|
* to a production org to confirm correctness, ensure code
|
|
* coverage, and prevent regressions. All Apex classes are
|
|
* required to have at least 75% code coverage in order to be deployed
|
|
* to a production org. In addition, all triggers must have some code coverage.
|
|
*
|
|
* The @isTest class annotation indicates this class only contains test
|
|
* methods. Classes defined with the @isTest annotation do not count against
|
|
* the org size limit for all Apex scripts.
|
|
*
|
|
* See the Apex Language Reference for more information about Testing and Code Coverage.
|
|
*/
|
|
@isTest
|
|
public class DropboxAuthTest {
|
|
|
|
private class DropboxTokenMock implements HttpCalloutMock {
|
|
|
|
public HTTPResponse respond(HTTPRequest req) {
|
|
|
|
HttpResponse res = new HttpResponse();
|
|
res.setStatusCode(200);
|
|
|
|
// Token endpoint call
|
|
if (req.getMethod() == 'POST') {
|
|
res.setBody('{"access_token":"testAccessToken","refresh_token":"testRefreshToken"}');
|
|
}
|
|
|
|
// fetchUserInfo call
|
|
else if (req.getMethod() == 'GET') {
|
|
res.setBody('{"email":"testuser@dropbox.com"}');
|
|
}
|
|
|
|
return res;
|
|
}
|
|
}
|
|
|
|
@isTest
|
|
static void testGetAccessTokenSuccess() {
|
|
|
|
// Set mock
|
|
Test.setMock(HttpCalloutMock.class, new DropboxTokenMock());
|
|
|
|
// Create instance of your auth class
|
|
// Replace DropboxAuth with your actual class name
|
|
DropboxAuth auth = new DropboxAuth();
|
|
|
|
Test.startTest();
|
|
auth.getAccessToken(
|
|
'dummyCode',
|
|
'Dropbox',
|
|
true,
|
|
UserInfo.getUserId()
|
|
);
|
|
Test.stopTest();
|
|
|
|
// If OAuthTokenManager.storeToken inserts record,
|
|
// you can optionally verify it here with SOQL
|
|
|
|
System.assert(true); // Method executed successfully
|
|
}
|
|
|
|
|
|
public class RefreshTokenMock implements HttpCalloutMock {
|
|
|
|
public HTTPResponse respond(HTTPRequest req) {
|
|
HttpResponse res = new HttpResponse();
|
|
res.setStatusCode(200);
|
|
res.setHeader('Content-Type', 'application/json');
|
|
res.setBody('{"access_token":"mock_access_token_123","token_type":"Bearer","expires_in":3600}');
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
@IsTest
|
|
static void testRefreshAccessToken() {
|
|
|
|
// Set Mock
|
|
Test.setMock(HttpCalloutMock.class, new RefreshTokenMock());
|
|
|
|
// Create instance of your class
|
|
DropboxAuth obj = new DropboxAuth();
|
|
|
|
Test.startTest();
|
|
String token = obj.refreshAccessToken('dummy_refresh_token');
|
|
Test.stopTest();
|
|
|
|
// Assert
|
|
System.assertEquals('mock_access_token_123', token);
|
|
}
|
|
|
|
|
|
|
|
|
|
} |