@@ -123,19 +123,20 @@ def _resource_response(content: bytes, file_name: str = "resource.bin", content_
123123 def test_parse_message_returns_callback_message (self ):
124124 client = self ._build_client ()
125125
126- result = client .parse_message (
127- {
128- "type" : "cardAction" ,
129- "callback_data" : "approve" ,
130- "message_id" : "om_123" ,
131- "chat_id" : "oc_123" ,
132- "sender" : {
133- "open_id" : "ou_user_1" ,
134- "user_id" : "u_user_1" ,
135- "name" : "tester" ,
136- },
137- }
138- )
126+ with patch ("app.modules.feishu.feishu.UserOper.get_name" , return_value = None ):
127+ result = client .parse_message (
128+ {
129+ "type" : "cardAction" ,
130+ "callback_data" : "approve" ,
131+ "message_id" : "om_123" ,
132+ "chat_id" : "oc_123" ,
133+ "sender" : {
134+ "open_id" : "ou_user_1" ,
135+ "user_id" : "u_user_1" ,
136+ "name" : "tester" ,
137+ },
138+ }
139+ )
139140
140141 self .assertIsNotNone (result )
141142 self .assertEqual (result .channel , MessageChannel .Feishu )
@@ -195,7 +196,9 @@ def build(self):
195196 def test_parse_message_blocks_non_admin_command (self ):
196197 client = self ._build_client (FEISHU_ADMINS = "ou_admin" )
197198
198- with patch .object (client , "send_text" , return_value = {"success" : True }) as send_text :
199+ with patch ("app.modules.feishu.feishu.UserOper.get_name" , return_value = None ), patch .object (
200+ client , "send_text" , return_value = {"success" : True }
201+ ) as send_text :
199202 result = client .parse_message (
200203 {
201204 "type" : "message" ,
@@ -217,6 +220,30 @@ def test_parse_message_blocks_non_admin_command(self):
217220 receive_id_type = "open_id" ,
218221 )
219222
223+ def test_parse_message_maps_feishu_ids_to_moviepilot_username (self ):
224+ client = self ._build_client ()
225+
226+ with patch ("app.modules.feishu.feishu.UserOper.get_name" , return_value = "moviepilot-user" ) as get_name :
227+ result = client .parse_message (
228+ {
229+ "type" : "message" ,
230+ "text" : "/ai 添加黑客帝国订阅" ,
231+ "sender" : {
232+ "open_id" : "ou_bound_user" ,
233+ "user_id" : "u_bound_user" ,
234+ "name" : "ou_bound_user" ,
235+ },
236+ }
237+ )
238+
239+ self .assertIsNotNone (result )
240+ self .assertEqual (result .userid , "ou_bound_user" )
241+ self .assertEqual (result .username , "moviepilot-user" )
242+ get_name .assert_called_once_with (
243+ feishu_openid = "ou_bound_user" ,
244+ feishu_userid = "u_bound_user" ,
245+ )
246+
220247 def test_send_notification_uses_direct_card_content (self ):
221248 client = self ._build_client ()
222249 client ._api_client , message_api = self ._build_message_api (
@@ -499,33 +526,34 @@ def test_close_streaming_card_updates_card_settings(self):
499526 def test_parse_message_supports_image_and_file_payloads (self ):
500527 client = self ._build_client ()
501528
502- image_message = client .parse_message (
503- {
504- "type" : "message" ,
505- "text" : "" ,
506- "images" : [{"ref" : "feishu://image/img_v2_test" }],
507- "message_id" : "om_img" ,
508- "chat_id" : "oc_chat" ,
509- "sender" : {
510- "open_id" : "ou_user_5" ,
511- "name" : "tester" ,
512- },
513- }
514- )
515-
516- file_message = client .parse_message (
517- {
518- "type" : "message" ,
519- "text" : "" ,
520- "files" : [{"ref" : "feishu://file/file_key/report.pdf" , "name" : "report.pdf" }],
521- "message_id" : "om_file" ,
522- "chat_id" : "oc_chat" ,
523- "sender" : {
524- "open_id" : "ou_user_6" ,
525- "name" : "tester" ,
526- },
527- }
528- )
529+ with patch ("app.modules.feishu.feishu.UserOper.get_name" , return_value = None ):
530+ image_message = client .parse_message (
531+ {
532+ "type" : "message" ,
533+ "text" : "" ,
534+ "images" : [{"ref" : "feishu://image/img_v2_test" }],
535+ "message_id" : "om_img" ,
536+ "chat_id" : "oc_chat" ,
537+ "sender" : {
538+ "open_id" : "ou_user_5" ,
539+ "name" : "tester" ,
540+ },
541+ }
542+ )
543+
544+ file_message = client .parse_message (
545+ {
546+ "type" : "message" ,
547+ "text" : "" ,
548+ "files" : [{"ref" : "feishu://file/file_key/report.pdf" , "name" : "report.pdf" }],
549+ "message_id" : "om_file" ,
550+ "chat_id" : "oc_chat" ,
551+ "sender" : {
552+ "open_id" : "ou_user_6" ,
553+ "name" : "tester" ,
554+ },
555+ }
556+ )
529557
530558 self .assertEqual (image_message .images [0 ].ref , "feishu://image/img_v2_test" )
531559 self .assertEqual (file_message .files [0 ].ref , "feishu://file/file_key/report.pdf" )
0 commit comments