Repository navigation
Expand file tree
/
Copy pathAppManifestTest.java
More file actions
155 lines (144 loc) · 6.95 KB
/
Copy pathAppManifestTest.java
File metadata and controls
155 lines (144 loc) · 6.95 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package test_locally.api.model;
import com.google.gson.Gson;
import com.slack.api.model.manifest.AppManifest;
import com.slack.api.model.manifest.AppManifestParams;
import org.junit.Test;
import test_locally.unit.GsonFactory;
import java.util.Arrays;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class AppManifestTest {
@Test
public void parser() {
String json = "{\n" +
" \"display_information\": {\n" +
" \"name\": \"manifest-sandbox\"\n" +
" },\n" +
" \"features\": {\n" +
" \"app_home\": {\n" +
" \"home_tab_enabled\": true,\n" +
" \"messages_tab_enabled\": false,\n" +
" \"messages_tab_read_only_enabled\": false\n" +
" },\n" +
" \"bot_user\": {\n" +
" \"display_name\": \"manifest-sandbox\",\n" +
" \"always_online\": true\n" +
" },\n" +
" \"shortcuts\": [\n" +
" {\n" +
" \"name\": \"message one\",\n" +
" \"type\": \"message\",\n" +
" \"callback_id\": \"m\",\n" +
" \"description\": \"message\"\n" +
" },\n" +
" {\n" +
" \"name\": \"global one\",\n" +
" \"type\": \"global\",\n" +
" \"callback_id\": \"g\",\n" +
" \"description\": \"global\"\n" +
" }\n" +
" ],\n" +
" \"slash_commands\": [\n" +
" {\n" +
" \"command\": \"/hey\",\n" +
" \"url\": \"https://www.example.com/\",\n" +
" \"description\": \"What's up?\",\n" +
" \"usage_hint\": \"What's up?\",\n" +
" \"should_escape\": true\n" +
" }\n" +
" ],\n" +
" \"unfurl_domains\": [\n" +
" \"example.com\"\n" +
" ]\n" +
" },\n" +
" \"oauth_config\": {\n" +
" \"redirect_urls\": [\n" +
" \"https://www.example.com/foo\"\n" +
" ],\n" +
" \"scopes\": {\n" +
" \"user\": [\n" +
" \"search:read\",\n" +
" \"channels:read\",\n" +
" \"groups:read\",\n" +
" \"mpim:read\"\n" +
" ],\n" +
" \"bot\": [\n" +
" \"commands\",\n" +
" \"incoming-webhook\",\n" +
" \"app_mentions:read\",\n" +
" \"links:read\"\n" +
" ]\n" +
" }\n" +
" },\n" +
" \"settings\": {\n" +
" \"allowed_ip_address_ranges\": [\n" +
" \"123.123.123.123/32\"\n" +
" ],\n" +
" \"event_subscriptions\": {\n" +
" \"request_url\": \"https://www.example.com/slack/events\",\n" +
" \"user_events\": [\n" +
" \"member_joined_channel\"\n" +
" ],\n" +
" \"bot_events\": [\n" +
" \"app_mention\",\n" +
" \"link_shared\"\n" +
" ]\n" +
" },\n" +
" \"interactivity\": {\n" +
" \"is_enabled\": true,\n" +
" \"request_url\": \"https://www.example.com/\",\n" +
" \"message_menu_options_url\": \"https://www.example.com/\"\n" +
" },\n" +
" \"org_deploy_enabled\": true,\n" +
" \"socket_mode_enabled\": false,\n" +
" \"token_rotation_enabled\": true\n" +
" }\n" +
"}";
AppManifest appManifest = GsonFactory.createSnakeCase(true, true)
.fromJson(json, AppManifest.class);
assertThat(appManifest.getSettings(), is(notNullValue()));
}
@Test
public void userConnections() {
String json = "{\n" +
" \"display_information\": {\n" +
" \"name\": \"connector\"\n" +
" },\n" +
" \"features\": {\n" +
" \"user_connections\": {\n" +
" \"is_enabled\": true,\n" +
" \"auth_hosts\": [\n" +
" \"example.com\",\n" +
" \"auth.example.com\"\n" +
" ]\n" +
" }\n" +
" }\n" +
"}";
Gson gson = GsonFactory.createSnakeCase(true, true);
AppManifest appManifest = gson.fromJson(json, AppManifest.class);
AppManifest.UserConnections userConnections = appManifest.getFeatures().getUserConnections();
assertThat(userConnections.getIsEnabled(), is(true));
assertThat(userConnections.getAuthHosts(), is(Arrays.asList("example.com", "auth.example.com")));
String serialized = gson.toJson(appManifest);
assertThat(serialized, containsString(
"\"user_connections\":{\"is_enabled\":true,\"auth_hosts\":[\"example.com\",\"auth.example.com\"]}"));
}
@Test
public void userConnectionsParams() {
AppManifestParams params = AppManifestParams.builder()
.features(AppManifestParams.Features.builder()
.userConnections(AppManifestParams.UserConnections.builder()
.isEnabled(false)
.authHosts(Arrays.asList("example.com"))
.build())
.build())
.build();
String serialized = GsonFactory.createSnakeCase(true, true).toJson(params);
assertThat(serialized, containsString(
"\"user_connections\":{\"is_enabled\":false,\"auth_hosts\":[\"example.com\"]}"));
}
}