-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsfApexTestClass
More file actions
45 lines (37 loc) · 1.94 KB
/
sfApexTestClass
File metadata and controls
45 lines (37 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
@isTest
public class TriggerSlackListWebhookTest {
@isTest
static void testSendToSlack() {
// Setup test data
TriggerSlackListWebhook.Request testRequest = new TriggerSlackListWebhook.Request();
testRequest.endpoint = 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX';
testRequest.message = 'Hello, this is a test message!';
testRequest.recordId = 'a1B2c3D4e5F6';
// Create a list of requests
List<TriggerSlackListWebhook.Request> requests = new List<TriggerSlackListWebhook.Request>{ testRequest };
// Set mock callout class
Test.setMock(HttpCalloutMock.class, new SlackCalloutMock());
// Test the method
Test.startTest();
TriggerSlackListWebhook.sendToSlack(requests);
Test.stopTest();
// Additional assertions can be added here if needed
// Example: assert on debug logs if the log handling is important
}
// Mock class implementing HttpCalloutMock
private class SlackCalloutMock implements HttpCalloutMock {
public HttpResponse respond(HttpRequest request) {
// Verify request method and endpoint
System.assertEquals('POST', request.getMethod());
System.assertEquals('https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX', request.getEndpoint());
// Verify the request body
String expectedBody = '{"text": "Hello, this is a test message!", "blocks": [{"type": "section", "fields": [{"type": "mrkdwn", "text": "Record ID: a1B2c3D4e5F6"}, {"type": "mrkdwn", "text": "Message: Hello, this is a test message!"}]}]}';
System.assertEquals(expectedBody, request.getBody());
// Create a fake response
HttpResponse response = new HttpResponse();
response.setStatusCode(200);
response.setBody('{"success": true}');
return response;
}
}
}