24
24
import static org .mockito .Mockito .verify ;
25
25
import static org .mockito .Mockito .when ;
26
26
27
- import com .github .seratch .jslack .app_backend .SlackSignature ;
28
27
import com .google .api .client .googleapis .json .GoogleJsonResponseException ;
29
28
import com .google .cloud .functions .HttpRequest ;
30
29
import com .google .cloud .functions .HttpResponse ;
31
30
import com .google .gson .Gson ;
31
+ import com .slack .api .app_backend .SlackSignature ;
32
32
import java .io .BufferedReader ;
33
33
import java .io .BufferedWriter ;
34
34
import java .io .IOException ;
@@ -91,8 +91,8 @@ public void onlyAcceptsPostRequestsTest() throws IOException, GeneralSecurityExc
91
91
92
92
@ Test
93
93
public void requiresSlackAuthHeadersTest () throws IOException , GeneralSecurityException {
94
- String jsonStr = gson . toJson ( Map . of ( "text" , " foo")) ;
95
- StringReader requestReadable = new StringReader (jsonStr );
94
+ String urlEncodedStr = "text= foo" ;
95
+ StringReader requestReadable = new StringReader (urlEncodedStr );
96
96
97
97
when (request .getMethod ()).thenReturn ("POST" );
98
98
when (request .getReader ()).thenReturn (new BufferedReader (requestReadable ));
@@ -105,7 +105,7 @@ public void requiresSlackAuthHeadersTest() throws IOException, GeneralSecurityEx
105
105
106
106
@ Test
107
107
public void recognizesValidSlackTokenTest () throws IOException , GeneralSecurityException {
108
- StringReader requestReadable = new StringReader ("{} " );
108
+ StringReader requestReadable = new StringReader ("" );
109
109
110
110
when (request .getReader ()).thenReturn (new BufferedReader (requestReadable ));
111
111
when (request .getMethod ()).thenReturn ("POST" );
@@ -117,8 +117,8 @@ public void recognizesValidSlackTokenTest() throws IOException, GeneralSecurityE
117
117
118
118
@ Test
119
119
public void handlesSearchErrorTest () throws IOException , GeneralSecurityException {
120
- String jsonStr = gson . toJson ( Map . of ( "text" , " foo")) ;
121
- StringReader requestReadable = new StringReader (jsonStr );
120
+ String urlEncodedStr = "text= foo" ;
121
+ StringReader requestReadable = new StringReader (urlEncodedStr );
122
122
123
123
when (request .getReader ()).thenReturn (new BufferedReader (requestReadable ));
124
124
when (request .getMethod ()).thenReturn ("POST" );
@@ -132,8 +132,8 @@ public void handlesSearchErrorTest() throws IOException, GeneralSecurityExceptio
132
132
133
133
@ Test
134
134
public void handlesEmptyKgResultsTest () throws IOException , GeneralSecurityException {
135
- String jsonStr = gson . toJson ( Map . of ( "text" , " asdfjkl13579")) ;
136
- StringReader requestReadable = new StringReader (jsonStr );
135
+ String urlEncodedStr = "text= asdfjkl13579" ;
136
+ StringReader requestReadable = new StringReader (urlEncodedStr );
137
137
138
138
when (request .getReader ()).thenReturn (new BufferedReader (requestReadable ));
139
139
when (request .getMethod ()).thenReturn ("POST" );
@@ -148,8 +148,24 @@ public void handlesEmptyKgResultsTest() throws IOException, GeneralSecurityExcep
148
148
149
149
@ Test
150
150
public void handlesPopulatedKgResultsTest () throws IOException , GeneralSecurityException {
151
- String jsonStr = gson .toJson (Map .of ("text" , "lion" ));
152
- StringReader requestReadable = new StringReader (jsonStr );
151
+ String urlEncodedStr = "text=lion" ;
152
+ StringReader requestReadable = new StringReader (urlEncodedStr );
153
+
154
+ when (request .getReader ()).thenReturn (new BufferedReader (requestReadable ));
155
+ when (request .getMethod ()).thenReturn ("POST" );
156
+
157
+ SlackSlashCommand functionInstance = new SlackSlashCommand (alwaysValidVerifier );
158
+
159
+ functionInstance .service (request , response );
160
+
161
+ writerOut .flush ();
162
+ assertThat (responseOut .toString ()).contains ("https://en.wikipedia.org/wiki/Lion" );
163
+ }
164
+
165
+ @ Test
166
+ public void handlesMultipleUrlParamsTest () throws IOException , GeneralSecurityException {
167
+ String urlEncodedStr = "unused=foo&text=lion" ;
168
+ StringReader requestReadable = new StringReader (urlEncodedStr );
153
169
154
170
when (request .getReader ()).thenReturn (new BufferedReader (requestReadable ));
155
171
when (request .getMethod ()).thenReturn ("POST" );
0 commit comments