function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BPOORBPOOR 

Using MultiStaticResourceCalloutMock class

I am working on a class that makes a callout to a third party API. The third party API needs to be authenticated with a OpenID Connect Auth token. So, in my class, I am making a callout to the OpenID Connect Auth service to get a bearer token and then I am making a callout to the third party API with the bearer token from OpenID Connect API. The third party API is providing some additional information about the fields on the Account object and I am updating the values on the Account object. There are multiple scenarios in this case.
  1. The values on the Account object is different from what is retrieved from the third party API. In this case, the values on the Account object are updated.
  2. The values on the Account object is same as what is retrieved from the third party API. In this case, the account is not updated.
  3. The third party API returns a blank response. So, the response body contains []. In this case, I am skipping the account.

The apex class is working fine. However, I need some help in building a test class for this. I am sure I need to use MultiStaticResourceCalloutMock stub class to build the test class, but I have some questions around it. My questions are below.
  1. Do I need to write three test methods, one for each scenario? 
  2. In each of the test methods, I assume I need to use MultiStaticResourceCalloutMock with two end points, one for OpenID Connect Auth and one for third party API, correct?
  3. I also need three static resources, one for successful response, one for blank response (the static resource file will contain [] only, and one with the response where the values are exactly same as what is on the Account, correct?


Can someone help?
 
ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

It is depends on the Apex class.If you have three different methods to compare the values to the Account records then you need to write three methods to cover the code.

However,if you have only one method in which you are comparing the values and updating in If clauses then you can simply do it in one method.

Best Practices:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri