|
1 | 1 | package test_locally.middleware; |
2 | 2 |
|
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | +import static org.junit.Assert.assertNotNull; |
| 5 | +import static org.junit.Assert.assertNull; |
| 6 | +import static util.MockSlackApi.InvalidToken; |
| 7 | +import static util.MockSlackApi.ValidToken; |
| 8 | + |
| 9 | +import util.MockSlackApiServer; |
| 10 | + |
| 11 | +import java.util.Collections; |
| 12 | +import java.util.HashMap; |
| 13 | +import java.util.List; |
| 14 | +import java.util.Map; |
| 15 | + |
| 16 | +import org.junit.Test; |
| 17 | + |
3 | 18 | import com.slack.api.Slack; |
4 | 19 | import com.slack.api.SlackConfig; |
5 | 20 | import com.slack.api.app_backend.events.payload.MemberJoinedChannelPayload; |
6 | 21 | import com.slack.api.app_backend.events.payload.MessagePayload; |
| 22 | +import com.slack.api.app_backend.events.payload.UserChangePayload; |
7 | 23 | import com.slack.api.bolt.middleware.MiddlewareChain; |
8 | 24 | import com.slack.api.bolt.middleware.builtin.IgnoringSelfEvents; |
9 | 25 | import com.slack.api.bolt.request.RequestHeaders; |
10 | 26 | import com.slack.api.bolt.request.builtin.EventRequest; |
11 | 27 | import com.slack.api.bolt.response.Response; |
12 | 28 | import com.slack.api.methods.MethodsClient; |
| 29 | +import com.slack.api.model.User; |
13 | 30 | import com.slack.api.model.event.MemberJoinedChannelEvent; |
14 | 31 | import com.slack.api.model.event.MessageEvent; |
| 32 | +import com.slack.api.model.event.UserChangeEvent; |
15 | 33 | import com.slack.api.util.json.GsonFactory; |
16 | | -import org.junit.Test; |
17 | | -import util.MockSlackApiServer; |
18 | | - |
19 | | -import java.util.Collections; |
20 | | -import java.util.HashMap; |
21 | | -import java.util.List; |
22 | | -import java.util.Map; |
23 | | - |
24 | | -import static org.junit.Assert.*; |
25 | | -import static util.MockSlackApi.InvalidToken; |
26 | | -import static util.MockSlackApi.ValidToken; |
27 | 34 |
|
28 | 35 | public class IgnoringSelfEventsTest { |
29 | 36 |
|
@@ -77,6 +84,30 @@ public String findAndSaveBotUserId(MethodsClient client, String botId) { |
77 | 84 | assertEquals(404L, result.getStatusCode().longValue()); |
78 | 85 | } |
79 | 86 |
|
| 87 | + @Test |
| 88 | + public void ignored_withUserObject() throws Exception { |
| 89 | + IgnoringSelfEvents middleware = new IgnoringSelfEvents(SlackConfig.DEFAULT) { |
| 90 | + @Override |
| 91 | + public String findAndSaveBotUserId(MethodsClient client, String botId) { |
| 92 | + return "U123BOT"; |
| 93 | + } |
| 94 | + }; |
| 95 | + Map<String, List<String>> rawHeaders = new HashMap<>(); |
| 96 | + RequestHeaders headers = new RequestHeaders(rawHeaders); |
| 97 | + UserChangePayload payload = new UserChangePayload(); |
| 98 | + payload.setTeamId("T123"); |
| 99 | + UserChangeEvent event = new UserChangeEvent(); |
| 100 | + User user = new User(); |
| 101 | + user.setId("U123BOT"); |
| 102 | + event.setUser(user); |
| 103 | + payload.setEvent(event); |
| 104 | + EventRequest req = new EventRequest(GsonFactory.createSnakeCase().toJson(payload), headers); |
| 105 | + req.getContext().setBotUserId("U123BOT"); |
| 106 | + Response resp = new Response(); |
| 107 | + Response result = middleware.apply(req, resp, chain); |
| 108 | + assertEquals(200L, result.getStatusCode().longValue()); |
| 109 | + } |
| 110 | + |
80 | 111 | @Test |
81 | 112 | public void not_ignored_no_botUserId() throws Exception { |
82 | 113 | IgnoringSelfEvents middleware = new IgnoringSelfEvents(SlackConfig.DEFAULT) { |
|
0 commit comments