@@ -2202,4 +2202,80 @@ public void buildCarouselBlock() {
22022202 assertThat (parsedCarousel .getElements ().get (0 ).getBlockId (), is ("card1" ));
22032203 assertThat (parsedCarousel .getElements ().get (0 ).getActions ().size (), is (1 ));
22042204 }
2205+
2206+ @ Test
2207+ public void parseTaskCardBlock () {
2208+ String json = "{\n " +
2209+ " \" blocks\" : [\n " +
2210+ " {\n " +
2211+ " \" type\" : \" task_card\" ,\n " +
2212+ " \" task_id\" : \" task_1\" ,\n " +
2213+ " \" title\" : \" Fetching weather data\" ,\n " +
2214+ " \" status\" : \" in_progress\" ,\n " +
2215+ " \" output\" : {\n " +
2216+ " \" type\" : \" rich_text\" ,\n " +
2217+ " \" elements\" : [\n " +
2218+ " {\n " +
2219+ " \" type\" : \" rich_text_section\" ,\n " +
2220+ " \" elements\" : [\n " +
2221+ " {\n " +
2222+ " \" type\" : \" text\" ,\n " +
2223+ " \" text\" : \" Found weather data for Chicago from 2 sources\" \n " +
2224+ " }\n " +
2225+ " ]\n " +
2226+ " }\n " +
2227+ " ]\n " +
2228+ " },\n " +
2229+ " \" sources\" : [\n " +
2230+ " {\n " +
2231+ " \" type\" : \" url\" ,\n " +
2232+ " \" url\" : \" https://weather.com/\" ,\n " +
2233+ " \" text\" : \" weather.com\" \n " +
2234+ " },\n " +
2235+ " {\n " +
2236+ " \" type\" : \" url\" ,\n " +
2237+ " \" url\" : \" https://www.accuweather.com/\" ,\n " +
2238+ " \" text\" : \" accuweather.com\" \n " +
2239+ " }\n " +
2240+ " ]\n " +
2241+ " }\n " +
2242+ " ]\n " +
2243+ "}" ;
2244+ Gson gson = GsonFactory .createSnakeCase ();
2245+ Message message = gson .fromJson (json , Message .class );
2246+ assertThat (message , is (notNullValue ()));
2247+ assertThat (message .getBlocks ().size (), is (1 ));
2248+
2249+ TaskCardBlock taskCard = (TaskCardBlock ) message .getBlocks ().get (0 );
2250+ assertThat (taskCard .getType (), is ("task_card" ));
2251+ assertThat (taskCard .getTaskId (), is ("task_1" ));
2252+ assertThat (taskCard .getTitle (), is ("Fetching weather data" ));
2253+ assertThat (taskCard .getStatus (), is ("in_progress" ));
2254+
2255+ assertThat (taskCard .getOutput (), is (notNullValue ()));
2256+ assertThat (taskCard .getOutput ().getType (), is ("rich_text" ));
2257+
2258+ assertThat (taskCard .getSources ().size (), is (2 ));
2259+ assertThat (taskCard .getSources ().get (0 ).getType (), is ("url" ));
2260+ assertThat (taskCard .getSources ().get (0 ).getUrl (), is ("https://weather.com/" ));
2261+ assertThat (taskCard .getSources ().get (0 ).getText (), is ("weather.com" ));
2262+ assertThat (taskCard .getSources ().get (1 ).getUrl (), is ("https://www.accuweather.com/" ));
2263+ assertThat (taskCard .getSources ().get (1 ).getText (), is ("accuweather.com" ));
2264+ }
2265+
2266+ @ Test
2267+ public void buildTaskCardBlock () {
2268+ TaskCardBlock taskCard = Blocks .taskCard (t -> t
2269+ .taskId ("task_42" )
2270+ .title ("Processing data" )
2271+ .status ("in_progress" )
2272+ .sources (Arrays .asList (
2273+ UrlSourceElement .builder ().url ("https://example.com" ).text ("example" ).build ())));
2274+ assertThat (taskCard , is (notNullValue ()));
2275+ assertThat (taskCard .getType (), is ("task_card" ));
2276+ assertThat (taskCard .getTaskId (), is ("task_42" ));
2277+ assertThat (taskCard .getTitle (), is ("Processing data" ));
2278+ assertThat (taskCard .getStatus (), is ("in_progress" ));
2279+ assertThat (taskCard .getSources ().size (), is (1 ));
2280+ }
22052281}
0 commit comments