Skip to content

Commit

Permalink
Merge pull request #23 from rollbar/wj-global-api-mock
Browse files Browse the repository at this point in the history
Publish API callout mock, so customer org tests will work.
  • Loading branch information
waltjones authored Jul 30, 2020
2 parents 74e2061 + 3089e0b commit dc94066
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
8 changes: 4 additions & 4 deletions force-app/main/default/tests/NotifierTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ public class NotifierTest {
@isTest
public static void testLogMessage(){
insert new RollbarSettings__c(SendReports__c = true);
Test.setMock(HttpCalloutMock.class, new RollbarApiCalloutMock());
RollbarTestHelper.setDefaultMock();

Config config = new Config('foo', 'bar');

Expand Down Expand Up @@ -31,7 +31,7 @@ public class NotifierTest {
@isTest
public static void testLogException(){
insert new RollbarSettings__c(SendReports__c = true);
Test.setMock(HttpCalloutMock.class, new RollbarApiCalloutMock());
RollbarTestHelper.setDefaultMock();

Config config = new Config('foo', 'bar');

Expand Down Expand Up @@ -61,7 +61,7 @@ public class NotifierTest {
@isTest
public static void testLogExceptionData(){
insert new RollbarSettings__c(SendReports__c = true);
Test.setMock(HttpCalloutMock.class, new RollbarApiCalloutMock());
RollbarTestHelper.setDefaultMock();

Config config = new Config('foo', 'bar');

Expand Down Expand Up @@ -101,7 +101,7 @@ public class NotifierTest {
@isTest
public static void testSendReportsDisabled(){
insert new RollbarSettings__c(SendReports__c = false);
Test.setMock(HttpCalloutMock.class, new RollbarApiCalloutMock());
RollbarTestHelper.setDefaultMock();

Config config = new Config('foo', 'bar');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ private class RollbarExceptionEmailHandlerTest {

@isTest
public static void testFlowEmail() {
Test.setMock(HttpCalloutMock.class, new RollbarApiVerifyTelemetryCalloutMock());
RollbarTestHelper.setMock(new RollbarApiVerifyTelemetryCalloutMock());

upsert new RollbarSettings__c(AccessToken__c = 'test-token', ReportFlowErrors__c = true);

Expand All @@ -23,7 +23,7 @@ private class RollbarExceptionEmailHandlerTest {

@isTest
public static void testFlowEmailDisabled() {
Test.setMock(HttpCalloutMock.class, new RollbarApiAssertNotCalledMock());
RollbarTestHelper.setMock(new RollbarApiAssertNotCalledMock());

upsert new RollbarSettings__c(AccessToken__c = 'test-token', ReportFlowErrors__c = false);

Expand Down
12 changes: 6 additions & 6 deletions force-app/main/default/tests/RollbarTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
public class RollbarTest {
@isTest
public static void testLogMessage() {
Test.setMock(HttpCalloutMock.class, new RollbarApiCalloutMock());
RollbarTestHelper.setDefaultMock();

insert new RollbarSettings__c(SendReports__c = true);

Expand All @@ -16,7 +16,7 @@ public class RollbarTest {

@isTest
public static void testLogMessageFuture() {
Test.setMock(HttpCalloutMock.class, new RollbarApiVerifyRequestCalloutMock());
RollbarTestHelper.setMock(new RollbarApiVerifyRequestCalloutMock());

insert new RollbarSettings__c(AccessToken__c = 'test-token', SendReports__c = true);

Expand All @@ -29,7 +29,7 @@ public class RollbarTest {

@isTest
public static void testLogMessageEvent() {
Test.setMock(HttpCalloutMock.class, new RollbarApiVerifyRequestCalloutMock());
RollbarTestHelper.setMock(new RollbarApiVerifyRequestCalloutMock());

insert new RollbarSettings__c(AccessToken__c = 'test-token', SendReports__c = true);

Expand All @@ -42,7 +42,7 @@ public class RollbarTest {

@isTest
public static void testLogMessageWithCustomDataAndTelemetry() {
Test.setMock(HttpCalloutMock.class, new RollbarApiCalloutMock());
RollbarTestHelper.setDefaultMock();

insert new RollbarSettings__c(SendReports__c = true);

Expand All @@ -65,7 +65,7 @@ public class RollbarTest {

@isTest
public static void testLogException() {
Test.setMock(HttpCalloutMock.class, new RollbarApiCalloutMock());
RollbarTestHelper.setDefaultMock();

insert new RollbarSettings__c(SendReports__c = true);

Expand All @@ -79,7 +79,7 @@ public class RollbarTest {

@isTest
public static void testLogExceptionData() {
Test.setMock(HttpCalloutMock.class, new RollbarApiCalloutMock());
RollbarTestHelper.setDefaultMock();

insert new RollbarSettings__c(SendReports__c = true);

Expand Down
10 changes: 10 additions & 0 deletions force-app/main/default/tests/RollbarTestHelper.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@isTest
global class RollbarTestHelper {
global static void setDefaultMock() {
Test.setMock(HttpCalloutMock.class, new RollbarApiCalloutMock());
}

global static void setMock(HttpCalloutMock mock) {
Test.setMock(HttpCalloutMock.class, mock);
}
}
5 changes: 5 additions & 0 deletions force-app/main/default/tests/RollbarTestHelper.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>45.0</apiVersion>
<status>Active</status>
</ApexClass>
1 change: 1 addition & 0 deletions manifest/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<members>RollbarApiVerifyRequestCalloutMock</members>
<members>RollbarApiVerifyTelemetryCalloutMock</members>
<members>DataBuilderTestException</members>
<members>RollbarTestHelper</members>
</types>

<types>
Expand Down

0 comments on commit dc94066

Please sign in to comment.