Testing Examples

The sample Apex SDK for Slack app contains an example implementation of the test harness.

These sections show sample app examples.

This example creates an account record and views it in a modal. It runs a test for the ViewRecordCommandDispatcher.cls Apex action in the sample app.

For these examples, assume that a basic test harness is set up and the methods are implemented as part of a Slack.BotClientMock.

This example test suite shows how to mock methods by using the test harness.

This example overwrites the bot clients conversationsCreate method. It requires a single Slack.ConversationsCreateRequest object as a parameter and returns a Slack.ConversationsCreateResponse object as the result. In this example, the Slack state is established in the test context to create a channel using the name from the request object. A successful response is returned with the new channel id and name.

See the Slack Documentation for more information on the conversations.create request and response objects.

This example overwrites the bot clients conversationsInvite method. It requires a single Slack.ConversationsInviteRequest object as a parameter and returns a Slack.ConversationsInviteResponse object as the result. In this example, the Slack state and the default team are established in the test context to invite the users specified in the request object to the designated channel. A successful response is returned.

See the Slack Documentation for more information on the conversations.invite request and response objects.

Orgs need to be on Spring '23 to use the getters associated with any request object.

This example overwrites the bot clients conversationsList method. It requires a single Slack.ConversationsListRequest object as a parameter and returns a Slack.ConversationsListResponse object as the result. In this example, the Slack state and default team are established in the test context to return the list of channels. A successful response is returned with a list of channels.

See the Slack Documentation for more information on the conversations.list request and response objects.

This example overwrites the bot clients conversationsInfo method. It requires a single Slack.ConversationsInfoRequest object as a parameter and returns a Slack.ConversationsInfoResponse object as the result. In this example, the super method is called to get information about the requested channel. The mocked topic value is added to the successful response. See the Slack Documentation for more information on the conversations.info request and response objects.

This example overwrites the bot clients pinsAdd method. It requires a single Slack.PinsAddRequest object as a parameter and returns a Slack.PinsAddResponse object as the result. In this example, the pin information from the request is added to a map that can be used to retrieve the information in a future request. When the request is made it's followed by returning a successful response. See the Slack Documentation for more information on the pins.add request and response objects.

This example overwrites the bot clients pinsList method. It requires a single Slack.PinsListRequest object as a parameter and returns a Slack.PinsListResponse object as the result. In this example, the pin information for the given channel specified in the request is removed and a successful response is returned with the list of pinned items. See the Slack Documentation for more information on the pins.list request and response objects.

This example overwrites the bot clients pinsRemove method. It requires a single Slack.PinsRemoveRequest object as a parameter and returns a Slack.PinsRemoveResponse object as the result. In this example, the pin information specified in the request is removed from the map containing the information and returned a successful response.
See the Slack Documentation for more information on the pins.remove request and response objects.