|
| 1 | +package test_locally.app_backend.interactive_components.payload; |
| 2 | + |
| 3 | +import com.slack.api.app_backend.interactive_components.payload.BlockSuggestionPayload; |
| 4 | +import com.slack.api.util.json.GsonFactory; |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +import static org.hamcrest.CoreMatchers.*; |
| 8 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 9 | + |
| 10 | +public class BlockSuggestionPayloadTest { |
| 11 | + |
| 12 | + // https://api.slack.com/messaging/interactivity/enabling |
| 13 | + String json = "{\n" + |
| 14 | + " \"type\": \"block_suggestion\",\n" + |
| 15 | + " \"user\": {\n" + |
| 16 | + " \"id\": \"U123\",\n" + |
| 17 | + " \"username\": \"seratch\",\n" + |
| 18 | + " \"name\": \"seratch\",\n" + |
| 19 | + " \"team_id\": \"T123\"\n" + |
| 20 | + " },\n" + |
| 21 | + " \"container\": {\n" + |
| 22 | + " \"type\": \"view\",\n" + |
| 23 | + " \"view_id\": \"V123\"\n" + |
| 24 | + " },\n" + |
| 25 | + " \"api_app_id\": \"A123\",\n" + |
| 26 | + " \"token\": \"legacy-fixed-value\",\n" + |
| 27 | + " \"action_id\": \"a\",\n" + |
| 28 | + " \"block_id\": \"b\",\n" + |
| 29 | + " \"value\": \"This is a test\",\n" + |
| 30 | + " \"team\": {\n" + |
| 31 | + " \"id\": \"T123\",\n" + |
| 32 | + " \"domain\": \"seratch\"\n" + |
| 33 | + " },\n" + |
| 34 | + " \"view\": {\n" + |
| 35 | + " \"id\": \"V123\",\n" + |
| 36 | + " \"team_id\": \"T123\",\n" + |
| 37 | + " \"type\": \"modal\",\n" + |
| 38 | + " \"blocks\": [\n" + |
| 39 | + " {\n" + |
| 40 | + " \"type\": \"input\",\n" + |
| 41 | + " \"block_id\": \"b\",\n" + |
| 42 | + " \"label\": {\n" + |
| 43 | + " \"type\": \"plain_text\",\n" + |
| 44 | + " \"text\": \"Label\",\n" + |
| 45 | + " \"emoji\": true\n" + |
| 46 | + " },\n" + |
| 47 | + " \"optional\": false,\n" + |
| 48 | + " \"element\": {\n" + |
| 49 | + " \"type\": \"external_select\",\n" + |
| 50 | + " \"action_id\": \"a\"\n" + |
| 51 | + " }\n" + |
| 52 | + " }\n" + |
| 53 | + " ],\n" + |
| 54 | + " \"private_metadata\": \"This is a secret\",\n" + |
| 55 | + " \"callback_id\": \"\",\n" + |
| 56 | + " \"state\": {\n" + |
| 57 | + " \"values\": {}\n" + |
| 58 | + " },\n" + |
| 59 | + " \"hash\": \"123.random\",\n" + |
| 60 | + " \"title\": {\n" + |
| 61 | + " \"type\": \"plain_text\",\n" + |
| 62 | + " \"text\": \"My App\",\n" + |
| 63 | + " \"emoji\": true\n" + |
| 64 | + " },\n" + |
| 65 | + " \"clear_on_close\": false,\n" + |
| 66 | + " \"notify_on_close\": false,\n" + |
| 67 | + " \"close\": {\n" + |
| 68 | + " \"type\": \"plain_text\",\n" + |
| 69 | + " \"text\": \"Cancel\",\n" + |
| 70 | + " \"emoji\": true\n" + |
| 71 | + " },\n" + |
| 72 | + " \"submit\": {\n" + |
| 73 | + " \"type\": \"plain_text\",\n" + |
| 74 | + " \"text\": \"Submit\",\n" + |
| 75 | + " \"emoji\": true\n" + |
| 76 | + " },\n" + |
| 77 | + " \"previous_view_id\": null,\n" + |
| 78 | + " \"root_view_id\": \"V123\",\n" + |
| 79 | + " \"app_id\": \"A123\",\n" + |
| 80 | + " \"external_id\": \"\",\n" + |
| 81 | + " \"app_installed_team_id\": \"T123\",\n" + |
| 82 | + " \"bot_id\": \"B123\"\n" + |
| 83 | + " }\n" + |
| 84 | + "}"; |
| 85 | + |
| 86 | + @Test |
| 87 | + public void deserialize() { |
| 88 | + BlockSuggestionPayload payload = GsonFactory.createSnakeCase().fromJson(json, BlockSuggestionPayload.class); |
| 89 | + assertThat(payload.getType(), is("block_suggestion")); |
| 90 | + assertThat(payload.getUser(), is(notNullValue())); |
| 91 | + assertThat(payload.getTeam(), is(notNullValue())); |
| 92 | + assertThat(payload.getContainer(), is(notNullValue())); |
| 93 | + assertThat(payload.getChannel(), is(nullValue())); |
| 94 | + |
| 95 | + assertThat(payload.getView(), is(notNullValue())); |
| 96 | + assertThat(payload.getView().getPrivateMetadata(), is("This is a secret")); |
| 97 | + } |
| 98 | + |
| 99 | +} |
0 commit comments