@@ -872,4 +872,129 @@ def loop_times(times)
872872 end
873873 end
874874 end
875+
876+ describe 'moderation' do
877+ before ( :each ) do
878+ @moderation = @client . moderation
879+ @test_user_id = SecureRandom . uuid
880+ @test_message_id = SecureRandom . uuid
881+ @test_config_key = SecureRandom . uuid
882+ end
883+
884+ it 'flagging a user and message' do
885+ msg_response = @channel . send_message ( { id : @test_message_id , text : 'Test message' } , @test_user_id )
886+ expect ( msg_response [ 'message' ] [ 'id' ] ) . to eq ( @test_message_id )
887+ expect ( msg_response [ 'message' ] [ 'user' ] [ 'id' ] ) . to eq ( @test_user_id )
888+ response = @moderation . flag_user (
889+ @test_user_id ,
890+ 'inappropriate_behavior' ,
891+ user_id : @random_user [ :id ] ,
892+ custom : { severity : 'high' }
893+ )
894+ expect ( response [ 'duration' ] ) . not_to be_nil
895+ response = @moderation . flag_message (
896+ @test_message_id ,
897+ 'inappropriate_content' ,
898+ user_id : @random_user [ :id ] ,
899+ custom : { category : 'spam' }
900+ )
901+ expect ( response [ 'duration' ] ) . not_to be_nil
902+ end
903+
904+ it 'mute a user and unmute a user' do
905+ @channel . send_message ( { id : @test_message_id , text : 'Test message' } , @test_user_id )
906+ testuserid1 = @random_user [ :id ]
907+ response = @moderation . mute_user (
908+ @test_user_id ,
909+ user_id : testuserid1 ,
910+ timeout : 60
911+ )
912+ expect ( response [ 'duration' ] ) . not_to be_nil
913+ expect ( response [ 'mutes' ] [ 0 ] [ 'user' ] [ 'id' ] ) . to eq ( testuserid1 )
914+ response = @moderation . unmute_user (
915+ @test_user_id ,
916+ user_id : @random_user [ :id ]
917+ )
918+ expect ( response [ 'duration' ] ) . not_to be_nil
919+
920+ response = @moderation . get_user_moderation_report (
921+ @test_user_id ,
922+ include_user_blocks : true ,
923+ include_user_mutes : true
924+ )
925+ expect ( response [ 'duration' ] ) . not_to be_nil
926+ end
927+
928+ it 'adds custom flags to an entity' do
929+ testuserid1 = @random_user [ :id ]
930+ testmsgid1 = SecureRandom . uuid
931+ @channel . send_message ( { id : testmsgid1 , text : 'Test message' } , testuserid1 )
932+ entity_type = 'stream:chat:v1:message'
933+ entity_id = testmsgid1
934+ entity_creator_id = testuserid1
935+ moderation_payload = {
936+ 'texts' => [ 'Test message' ] ,
937+ 'custom' => { 'original_message_type' => 'regular' }
938+ }
939+ flags = [ { type : 'custom_check_text' , value : 'test_flag' } ]
940+
941+ response = @moderation . add_custom_flags ( entity_type , entity_id , entity_creator_id , moderation_payload , flags )
942+ expect ( response [ 'duration' ] ) . not_to be_nil
943+ response = @moderation . add_custom_message_flags (
944+ testmsgid1 ,
945+ [ { type : 'custom_check_text' , value : 'test_flag' } ]
946+ )
947+ expect ( response [ 'duration' ] ) . not_to be_nil
948+ end
949+
950+ it 'config test' do
951+ blocklist_name = "blocklist-#{ SecureRandom . uuid } "
952+ words = %w[ pretty crazy ]
953+
954+ # Create blocklist
955+ response = @client . create_blocklist ( blocklist_name , words )
956+ expect ( response [ 'duration' ] ) . not_to be_nil
957+
958+ # Create moderation config
959+ moderation_config = {
960+ key : "chat:team:#{ @channel . id } " ,
961+ block_list_config : {
962+ enabled : true ,
963+ rules : [
964+ {
965+ name : response [ 'blocklist' ] [ 'name' ] ,
966+ action : 'flag'
967+ }
968+ ]
969+ }
970+ }
971+ @moderation . upsert_config ( moderation_config )
972+ response = @moderation . get_config ( "chat:team:#{ @channel . id } " )
973+ expect ( response [ 'config' ] [ 'key' ] ) . to eq ( "chat:team:#{ @channel . id } " )
974+
975+ response = @moderation . query_configs (
976+ { key : "chat:team:#{ @channel . id } " } ,
977+ [ ]
978+ )
979+ expect ( response ) . not_to be_nil
980+
981+ # Send message that should be blocked
982+
983+ response = @channel . send_message (
984+ { text : 'crazy game ever' } ,
985+ @random_user [ :id ] ,
986+ force_moderation : true
987+ )
988+
989+ # # Verify message appears in review queue
990+ queue_response = @moderation . query_review_queue (
991+ { entity_type : 'stream:chat:v1:message' } ,
992+ { created_at : -1 } ,
993+ limit : 1
994+ )
995+ expect ( queue_response [ 'items' ] [ 0 ] [ 'entity_id' ] ) . to eq ( response [ 'message' ] [ 'id' ] )
996+
997+ @moderation . delete_config ( "chat:team:#{ @channel . id } " )
998+ end
999+ end
8751000end
0 commit comments