2121import org .junit .BeforeClass ;
2222import org .junit .Test ;
2323
24- import java .util .Arrays ;
25- import java .util .Collections ;
2624import java .util .List ;
2725
26+ import static java .util .Collections .singletonList ;
27+ import static org .hamcrest .CoreMatchers .containsString ;
2828import static org .hamcrest .CoreMatchers .is ;
2929import static org .hamcrest .CoreMatchers .notNullValue ;
3030import static org .hamcrest .CoreMatchers .nullValue ;
@@ -52,11 +52,7 @@ public static void tearDown() throws InterruptedException {
5252 public void channel_canvases () throws Exception {
5353 MethodsClient client = slack .methods (botToken );
5454
55- ConversationsCreateResponse newChannel = client .conversationsCreate (r -> r .name ("test-" + System .currentTimeMillis ()));
56- assertThat (newChannel .getError (), is (nullValue ()));
57- String channelId = newChannel .getChannel ().getId ();
58-
59- Thread .sleep (500L ); // To avoid occasional 500 errors
55+ String channelId = createChannel (client );
6056
6157 ConversationsCanvasesCreateResponse creation = client .conversationsCanvasesCreate (r -> r
6258 .channelId (channelId )
@@ -72,9 +68,7 @@ public void channel_canvases() throws Exception {
7268 );
7369 assertThat (creation .getError (), is (nullValue ()));
7470
75- String canvasId = creation .getCanvasId ();
76- List <String > userIds = Arrays .asList (client .authTest (r -> r ).getUserId ());
77- FilesInfoResponse details = verifyCanvasOps (client , canvasId , channelId , userIds );
71+ FilesInfoResponse details = verifyCanvasOps (client , creation .getCanvasId ());
7872 ChatPostMessageResponse message = client .chatPostMessage (r -> r
7973 .channel (channelId )
8074 .text ("Here you are: " + details .getFile ().getPermalink ())
@@ -101,8 +95,8 @@ public void standalone_canvases() throws Exception {
10195
10296 String canvasId = creation .getCanvasId ();
10397 try {
104- List <String > userIds = Arrays . asList (client .authTest (r -> r ).getUserId ());
105- verifyCanvasOps (client , canvasId , null , userIds );
98+ List <String > userIds = singletonList (client .authTest (r -> r ).getUserId ());
99+ verifyCanvasOps (client , canvasId );
106100
107101 CanvasesAccessSetResponse set = client .canvasesAccessSet (r -> r
108102 .canvasId (canvasId )
@@ -122,11 +116,11 @@ public void standalone_canvases() throws Exception {
122116 }
123117 }
124118
125- FilesInfoResponse verifyCanvasOps (MethodsClient client , String canvasId , String channelId , List < String > userIds ) throws Exception {
119+ FilesInfoResponse verifyCanvasOps (MethodsClient client , String canvasId ) throws Exception {
126120 CanvasesSectionsLookupResponse lookupResult = client .canvasesSectionsLookup (r -> r
127121 .canvasId (canvasId )
128122 .criteria (CanvasesSectionsLookupRequest .Criteria .builder ()
129- .sectionTypes (Arrays . asList (CanvasDocumentSectionType .H2 ))
123+ .sectionTypes (singletonList (CanvasDocumentSectionType .H2 ))
130124 .containsText ("Before" )
131125 .build ()
132126 )
@@ -136,7 +130,7 @@ FilesInfoResponse verifyCanvasOps(MethodsClient client, String canvasId, String
136130 String sectionId = lookupResult .getSections ().get (0 ).getId ();
137131 CanvasesEditResponse edit = client .canvasesEdit (r -> r
138132 .canvasId (canvasId )
139- .changes (Arrays . asList (CanvasDocumentChange .builder ()
133+ .changes (singletonList (CanvasDocumentChange .builder ()
140134 .sectionId (sectionId )
141135 .operation (CanvasEditOperation .REPLACE )
142136 .documentContent (CanvasDocumentContent .builder ().markdown ("## After" ).build ())
@@ -166,30 +160,47 @@ public void standalone_canvases_error() throws Exception {
166160 @ Test
167161 public void error_detail () throws Exception {
168162 MethodsClient client = slack .methods (botToken );
169- // canvases.create
170- {
171- CanvasesCreateResponse response = client .canvasesCreate (r -> r
172- .title ("test" )
173- .documentContent (CanvasDocumentContent .builder ()
174- .markdown ("test" )
175- .type ("invalid" )
176- .build ())
177- );
178- assertThat (response .isOk (), is (false ));
179- assertThat (response .getError (), is ("invalid_arguments" ));
180- assertThat (response .getDetail (), is (notNullValue ()));
181- }
182- // canvases.edit
183- {
184- CanvasesEditResponse response = client .canvasesEdit (r -> r
185- .canvasId ("F123" )
186- .changes (Collections .singletonList (CanvasDocumentChange .builder ()
187- .documentContent (CanvasDocumentContent .builder ().markdown ("foo" ).type ("invalid" ).build ())
188- .build ()))
189- );
190- assertThat (response .isOk (), is (false ));
191- assertThat (response .getError (), is ("invalid_arguments" ));
192- assertThat (response .getDetail (), is (notNullValue ()));
193- }
163+
164+ String channelId = createChannel (client );
165+
166+ String invalidCanvasContent = "1. Text\n * Nested" ; // mixing of ordered and unordered lists is not supported
167+ ConversationsCanvasesCreateResponse failedCreation = client .conversationsCanvasesCreate (r -> r
168+ .channelId (channelId )
169+ .documentContent (CanvasDocumentContent .builder ()
170+ .markdown (invalidCanvasContent )
171+ .build ())
172+ );
173+ assertThat (failedCreation .isOk (), is (false ));
174+ assertThat (failedCreation .getError (), is ("canvas_creation_failed" ));
175+ assertThat (failedCreation .getDetail (), containsString ("Unsupported list type" ));
176+
177+ ConversationsCanvasesCreateResponse successfulCreation = client .conversationsCanvasesCreate (r -> r
178+ .channelId (channelId )
179+ .documentContent (CanvasDocumentContent .builder ()
180+ .markdown ("Correct MD" )
181+ .build ()
182+ )
183+ );
184+ assertThat (successfulCreation .getCanvasId (), is (notNullValue ()));
185+
186+ CanvasesEditResponse editFailingResponse = client .canvasesEdit (r -> r
187+ .canvasId (successfulCreation .getCanvasId ())
188+ .changes (singletonList (CanvasDocumentChange .builder ()
189+ .operation (CanvasEditOperation .REPLACE )
190+ .documentContent (CanvasDocumentContent .builder ().markdown (invalidCanvasContent ).build ())
191+ .build ()))
192+ );
193+ assertThat (editFailingResponse .isOk (), is (false ));
194+ assertThat (editFailingResponse .getError (), is ("canvas_editing_failed" ));
195+ assertThat (editFailingResponse .getDetail (), containsString ("Unsupported list type" ));
196+ }
197+
198+ private static String createChannel (MethodsClient client ) throws Exception {
199+ ConversationsCreateResponse newChannel = client .conversationsCreate (r -> r .name ("test-" + System .currentTimeMillis ()));
200+ assertThat (newChannel .getError (), is (nullValue ()));
201+ String channelId = newChannel .getChannel ().getId ();
202+
203+ Thread .sleep (500L ); // To avoid occasional 500 errors
204+ return channelId ;
194205 }
195206}
0 commit comments