11package io .getstream .client ;
22
3+ import static org .junit .Assert .assertEquals ;
4+ import static org .junit .Assert .assertNotNull ;
5+ import static org .junit .Assert .assertNull ;
6+
37import com .google .common .collect .ImmutableMap ;
48import io .getstream .core .KeepHistory ;
59import io .getstream .core .models .*;
@@ -163,29 +167,54 @@ public void partiallyUpdateActivitiesByForeignID() throws Exception {
163167 }
164168
165169 @ Test
166- public void partiallyUpdateActivityByIDWithRequestOptions () throws Exception {
170+ public void partiallyUpdateActivityByIDSkipModeration () throws Exception {
167171 Client client = Client .builder (apiKey , secret ).build ();
168172
169- Map <String , Object > set = ImmutableMap .of ("value" , "message" );
170- Iterable <String > unset = Collections .emptyList ();
171- Activity result =
173+ Activity activity =
174+ Activity .builder ()
175+ .actor ("test" )
176+ .verb ("test" )
177+ .object ("test" )
178+ .moderationTemplate ("moderation_template_activity" )
179+ .extraField ("text" , "safe text" )
180+ .foreignID (UUID .randomUUID ().toString ())
181+ .time (new Date ())
182+ .build ();
183+ Activity created = client .flatFeed ("user" , "1" ).addActivity (activity ).join ();
184+ assertNotNull (created .getModerationResponse ());
185+ assertEquals ("keep" , created .getModerationResponse ().getRecommendedAction ());
186+
187+ Activity updated =
172188 client
173189 .updateActivityByID (
174- "1657b300-a648-11d5-8080-800020fde6c3" ,
175- set ,
190+ created . getID () ,
191+ ImmutableMap . of ( "text" , "pissoar" ) ,
176192 new String [0 ],
177193 new CustomQueryParameter ("skip_moderation" , "true" ))
178194 .join ();
195+ assertNull (updated .getModerationResponse ());
179196 }
180197
181198 @ Test
182- public void partiallyUpdateActivitiesByIDWithRequestOptions () throws Exception {
199+ public void partiallyUpdateActivitiesByIDSkipModeration () throws Exception {
183200 Client client = Client .builder (apiKey , secret ).build ();
184201
202+ Activity activity =
203+ Activity .builder ()
204+ .actor ("test" )
205+ .verb ("test" )
206+ .object ("test" )
207+ .moderationTemplate ("moderation_template_activity" )
208+ .extraField ("text" , "safe text" )
209+ .foreignID (UUID .randomUUID ().toString ())
210+ .time (new Date ())
211+ .build ();
212+ Activity created = client .flatFeed ("user" , "1" ).addActivity (activity ).join ();
213+
185214 ActivityUpdate update =
186215 ActivityUpdate .builder ()
187- .id ("1657b300-a648-11d5-8080-800020fde6c3" )
188- .set (ImmutableMap .of ("value " , "message " ))
216+ .id (created . getID () )
217+ .set (ImmutableMap .of ("text " , "pissoar " ))
189218 .unset (Collections .emptyList ())
190219 .build ();
191220
@@ -195,39 +224,67 @@ public void partiallyUpdateActivitiesByIDWithRequestOptions() throws Exception {
195224 new ActivityUpdate [] {update },
196225 new CustomQueryParameter ("skip_moderation" , "true" ))
197226 .join ();
227+ assertEquals (1 , result .size ());
228+ assertNull (result .get (0 ).getModerationResponse ());
198229 }
199230
200231 @ Test
201- public void partiallyUpdateActivityByForeignIDWithRequestOptions () throws Exception {
232+ public void partiallyUpdateActivityByForeignIDSkipModeration () throws Exception {
202233 Client client = Client .builder (apiKey , secret ).build ();
203234
204- SimpleDateFormat isoFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.S" );
205- isoFormat .setTimeZone (TimeZone .getTimeZone ("UTC" ));
206- Date time = isoFormat .parse ("2001-09-11T00:01:02.000000" );
235+ String foreignID = UUID .randomUUID ().toString ();
236+ Date time = new Date ();
207237
208- Activity result =
238+ Activity activity =
239+ Activity .builder ()
240+ .actor ("test" )
241+ .verb ("test" )
242+ .object ("test" )
243+ .moderationTemplate ("moderation_template_activity" )
244+ .extraField ("text" , "safe text" )
245+ .foreignID (foreignID )
246+ .time (time )
247+ .build ();
248+ Activity created = client .flatFeed ("user" , "1" ).addActivity (activity ).join ();
249+ assertNotNull (created .getModerationResponse ());
250+ assertEquals ("keep" , created .getModerationResponse ().getRecommendedAction ());
251+
252+ Activity updated =
209253 client
210254 .updateActivityByForeignID (
211- " foreignID" ,
255+ foreignID ,
212256 time ,
213- ImmutableMap .of ("value " , "message " ),
257+ ImmutableMap .of ("text " , "pissoar " ),
214258 new String [0 ],
215259 new CustomQueryParameter ("skip_moderation" , "true" ))
216260 .join ();
261+ assertNull (updated .getModerationResponse ());
217262 }
218263
219264 @ Test
220- public void partiallyUpdateActivitiesByForeignIDWithRequestOptions () throws Exception {
265+ public void partiallyUpdateActivitiesByForeignIDSkipModeration () throws Exception {
221266 Client client = Client .builder (apiKey , secret ).build ();
222267
223- SimpleDateFormat isoFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.S" );
224- isoFormat .setTimeZone (TimeZone .getTimeZone ("UTC" ));
268+ String foreignID = UUID .randomUUID ().toString ();
269+ Date time = new Date ();
270+
271+ Activity activity =
272+ Activity .builder ()
273+ .actor ("test" )
274+ .verb ("test" )
275+ .object ("test" )
276+ .moderationTemplate ("moderation_template_activity" )
277+ .extraField ("text" , "safe text" )
278+ .foreignID (foreignID )
279+ .time (time )
280+ .build ();
281+ client .flatFeed ("user" , "1" ).addActivity (activity ).join ();
225282
226283 ActivityUpdate update =
227284 ActivityUpdate .builder ()
228- .foreignID (" foreignID" )
229- .time (isoFormat . parse ( "2001-09-11T00:01:02.000000" ) )
230- .set (ImmutableMap .of ("value " , "message " ))
285+ .foreignID (foreignID )
286+ .time (time )
287+ .set (ImmutableMap .of ("text " , "pissoar " ))
231288 .unset (Collections .emptyList ())
232289 .build ();
233290
@@ -237,6 +294,8 @@ public void partiallyUpdateActivitiesByForeignIDWithRequestOptions() throws Exce
237294 new ActivityUpdate [] {update },
238295 new CustomQueryParameter ("skip_moderation" , "true" ))
239296 .join ();
297+ assertEquals (1 , result .size ());
298+ assertNull (result .get (0 ).getModerationResponse ());
240299 }
241300
242301 @ Test
0 commit comments