Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish API callout mock, so customer org tests will work. #23

Merged
merged 1 commit into from
Jul 30, 2020

Conversation

waltjones
Copy link
Contributor

@waltjones waltjones commented Jul 29, 2020

Salesforce won't let users of managed packages call Test.setMock for callouts in the managed package. Yet they also require that all callouts are mocked.

This PR provides a wrapper so Test.setMock can be called within the package, making it possible to mock the API calls.

The Rollbar package tests are also updated to use this helper class internally.

The user tests can use:

rollbar.RollbarTestHelper.setDefaultMock();

Or

rollbar.RollbarTestHelper.setMock(new CustomMock);

Example:

@isTest
public class CalloutTest {
    @isTest
    public static void calloutIsMocked(){
        // Set the test mock.
        rollbar.RollbarTestHelper.setDefaultMock();

        // Also initialize a test token. (Can be any string.)
        insert new rollbar__RollbarSettings__c(rollbar__AccessToken__c = 'test-token');
        
        Test.startTest();
        // Any Rollbar callouts (e.g. rollbar.Rollbar.log()) should work.
        Test.stopTest();
    }
}

Copy link

@ajtran ajtran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks alright to me!

@waltjones waltjones merged commit dc94066 into master Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants