@@ -676,6 +676,7 @@ fn to_json<T: serde::Serialize>(outcome: RpcOutcome<T>) -> Result<Value, String>
676676#[ cfg( test) ]
677677mod tests {
678678 use super :: * ;
679+ use serde_json:: json;
679680
680681 #[ test]
681682 fn schema_handler_parity ( ) {
@@ -781,4 +782,229 @@ mod tests {
781782 // schema must still exist with outputs.
782783 assert ! ( !s. outputs. is_empty( ) ) ;
783784 }
785+
786+ #[ test]
787+ fn connect_schema_requires_channel_auth_mode ( ) {
788+ let s = schemas ( "connect" ) ;
789+ let required: Vec < & str > = s
790+ . inputs
791+ . iter ( )
792+ . filter ( |f| f. required )
793+ . map ( |f| f. name )
794+ . collect ( ) ;
795+ assert ! ( required. contains( & "channel" ) ) ;
796+ assert ! ( required. contains( & "authMode" ) ) ;
797+ }
798+
799+ #[ test]
800+ fn disconnect_schema_requires_channel_auth_mode ( ) {
801+ let s = schemas ( "disconnect" ) ;
802+ let required: Vec < & str > = s
803+ . inputs
804+ . iter ( )
805+ . filter ( |f| f. required )
806+ . map ( |f| f. name )
807+ . collect ( ) ;
808+ assert ! ( required. contains( & "channel" ) ) ;
809+ assert ! ( required. contains( & "authMode" ) ) ;
810+ }
811+
812+ #[ test]
813+ fn status_schema_has_optional_channel ( ) {
814+ let s = schemas ( "status" ) ;
815+ let chan = s. inputs . iter ( ) . find ( |f| f. name == "channel" ) ;
816+ assert ! ( chan. is_some_and( |f| !f. required) ) ;
817+ }
818+
819+ #[ test]
820+ fn test_schema_requires_channel_auth_mode_credentials ( ) {
821+ let s = schemas ( "test" ) ;
822+ let required: Vec < & str > = s
823+ . inputs
824+ . iter ( )
825+ . filter ( |f| f. required )
826+ . map ( |f| f. name )
827+ . collect ( ) ;
828+ assert ! ( required. contains( & "channel" ) ) ;
829+ assert ! ( required. contains( & "authMode" ) ) ;
830+ assert ! ( required. contains( & "credentials" ) ) ;
831+ }
832+
833+ #[ test]
834+ fn list_schema_has_no_inputs ( ) {
835+ let s = schemas ( "list" ) ;
836+ assert ! ( s. inputs. is_empty( ) ) ;
837+ }
838+
839+ #[ test]
840+ fn discord_link_start_schema ( ) {
841+ let s = schemas ( "discord_link_start" ) ;
842+ assert_eq ! ( s. namespace, "channels" ) ;
843+ assert_eq ! ( s. function, "discord_link_start" ) ;
844+ }
845+
846+ #[ test]
847+ fn discord_link_check_requires_link_token ( ) {
848+ let s = schemas ( "discord_link_check" ) ;
849+ let required: Vec < & str > = s
850+ . inputs
851+ . iter ( )
852+ . filter ( |f| f. required )
853+ . map ( |f| f. name )
854+ . collect ( ) ;
855+ assert ! ( required. contains( & "linkToken" ) ) ;
856+ }
857+
858+ #[ test]
859+ fn discord_list_channels_requires_guild_id ( ) {
860+ let s = schemas ( "discord_list_channels" ) ;
861+ let required: Vec < & str > = s
862+ . inputs
863+ . iter ( )
864+ . filter ( |f| f. required )
865+ . map ( |f| f. name )
866+ . collect ( ) ;
867+ assert ! ( required. contains( & "guildId" ) ) ;
868+ }
869+
870+ #[ test]
871+ fn discord_check_permissions_requires_guild_and_channel ( ) {
872+ let s = schemas ( "discord_check_permissions" ) ;
873+ let required: Vec < & str > = s
874+ . inputs
875+ . iter ( )
876+ . filter ( |f| f. required )
877+ . map ( |f| f. name )
878+ . collect ( ) ;
879+ assert ! ( required. contains( & "guildId" ) ) ;
880+ assert ! ( required. contains( & "channelId" ) ) ;
881+ }
882+
883+ #[ test]
884+ fn send_reaction_requires_channel_and_reaction ( ) {
885+ let s = schemas ( "send_reaction" ) ;
886+ let required: Vec < & str > = s
887+ . inputs
888+ . iter ( )
889+ . filter ( |f| f. required )
890+ . map ( |f| f. name )
891+ . collect ( ) ;
892+ assert ! ( required. contains( & "channel" ) ) ;
893+ assert ! ( required. contains( & "reaction" ) ) ;
894+ }
895+
896+ #[ test]
897+ fn create_thread_requires_channel_and_title ( ) {
898+ let s = schemas ( "create_thread" ) ;
899+ let required: Vec < & str > = s
900+ . inputs
901+ . iter ( )
902+ . filter ( |f| f. required )
903+ . map ( |f| f. name )
904+ . collect ( ) ;
905+ assert ! ( required. contains( & "channel" ) ) ;
906+ assert ! ( required. contains( & "title" ) ) ;
907+ }
908+
909+ #[ test]
910+ fn update_thread_requires_channel_thread_id_action ( ) {
911+ let s = schemas ( "update_thread" ) ;
912+ let required: Vec < & str > = s
913+ . inputs
914+ . iter ( )
915+ . filter ( |f| f. required )
916+ . map ( |f| f. name )
917+ . collect ( ) ;
918+ assert ! ( required. contains( & "channel" ) ) ;
919+ assert ! ( required. contains( & "threadId" ) ) ;
920+ assert ! ( required. contains( & "action" ) ) ;
921+ }
922+
923+ #[ test]
924+ fn list_threads_requires_channel ( ) {
925+ let s = schemas ( "list_threads" ) ;
926+ let required: Vec < & str > = s
927+ . inputs
928+ . iter ( )
929+ . filter ( |f| f. required )
930+ . map ( |f| f. name )
931+ . collect ( ) ;
932+ assert ! ( required. contains( & "channel" ) ) ;
933+ }
934+
935+ #[ test]
936+ fn telegram_login_start_schema_has_no_inputs ( ) {
937+ let s = schemas ( "telegram_login_start" ) ;
938+ assert ! ( s. inputs. is_empty( ) ) ;
939+ }
940+
941+ #[ test]
942+ fn deserialize_connect_params ( ) {
943+ let params: ConnectParams = serde_json:: from_value ( json ! ( {
944+ "channel" : "telegram" ,
945+ "authMode" : "bot_token"
946+ } ) )
947+ . unwrap ( ) ;
948+ assert_eq ! ( params. channel, "telegram" ) ;
949+ assert_eq ! ( params. auth_mode, "bot_token" ) ;
950+ assert ! ( params. credentials. is_none( ) ) ;
951+ }
952+
953+ #[ test]
954+ fn deserialize_disconnect_params ( ) {
955+ let params: DisconnectParams = serde_json:: from_value ( json ! ( {
956+ "channel" : "discord" ,
957+ "authMode" : "bot_token"
958+ } ) )
959+ . unwrap ( ) ;
960+ assert_eq ! ( params. channel, "discord" ) ;
961+ }
962+
963+ #[ test]
964+ fn deserialize_status_params_empty ( ) {
965+ let params: StatusParams = serde_json:: from_value ( json ! ( { } ) ) . unwrap ( ) ;
966+ assert ! ( params. channel. is_none( ) ) ;
967+ }
968+
969+ #[ test]
970+ fn deserialize_status_params_with_channel ( ) {
971+ let params: StatusParams = serde_json:: from_value ( json ! ( { "channel" : "telegram" } ) ) . unwrap ( ) ;
972+ assert_eq ! ( params. channel. as_deref( ) , Some ( "telegram" ) ) ;
973+ }
974+
975+ #[ test]
976+ fn deserialize_send_message_params ( ) {
977+ let params: SendMessageParams = serde_json:: from_value ( json ! ( {
978+ "channel" : "telegram" ,
979+ "message" : { "text" : "hello" }
980+ } ) )
981+ . unwrap ( ) ;
982+ assert_eq ! ( params. channel, "telegram" ) ;
983+ }
984+
985+ #[ test]
986+ fn to_json_helper ( ) {
987+ let outcome = RpcOutcome :: single_log ( json ! ( { "ok" : true } ) , "log" ) ;
988+ assert ! ( to_json( outcome) . is_ok( ) ) ;
989+ }
990+
991+ #[ test]
992+ fn required_string_helper ( ) {
993+ let f = required_string ( "channel" , "channel name" ) ;
994+ assert ! ( f. required) ;
995+ assert ! ( matches!( f. ty, TypeSchema :: String ) ) ;
996+ }
997+
998+ #[ test]
999+ fn optional_string_helper ( ) {
1000+ let f = optional_string ( "auth_mode" , "auth" ) ;
1001+ assert ! ( !f. required) ;
1002+ }
1003+
1004+ #[ test]
1005+ fn json_output_helper ( ) {
1006+ let f = json_output ( "result" , "the result" ) ;
1007+ assert ! ( f. required) ;
1008+ assert ! ( matches!( f. ty, TypeSchema :: Json ) ) ;
1009+ }
7841010}
0 commit comments