kaikai_test/tests/test_robot_service.py
2026-05-07 18:12:43 +08:00

45 lines
1.5 KiB
Python

from __future__ import annotations
import json
import unittest
from daily_report.robot_service import create_reminder_payload, create_summary_payload, create_webhook_sign
class RobotServiceTest(unittest.TestCase):
def test_creates_reminder_payload_with_submit_link(self) -> None:
payload = create_reminder_payload("http://localhost:8787/submit", "每日工作汇报提醒")
text = json.dumps(payload, ensure_ascii=False)
self.assertEqual(payload["msg_type"], "interactive")
self.assertIn("每日工作汇报提醒", text)
self.assertIn("http://localhost:8787/submit", text)
def test_creates_summary_payload_with_missing_employees(self) -> None:
payload = create_summary_payload(
"http://localhost:8787/manager",
{
"date": "2026-05-07",
"expectedCount": 2,
"submittedCount": 1,
"missingCount": 1,
"missing": [{"name": "Chen"}],
},
)
text = json.dumps(payload, ensure_ascii=False)
self.assertIn("2026-05-07", text)
self.assertIn("1/2", text)
self.assertIn("Chen", text)
self.assertIn("http://localhost:8787/manager", text)
def test_creates_webhook_signature(self) -> None:
signature = create_webhook_sign("1599360473", "test-secret")
self.assertIsInstance(signature, str)
self.assertGreater(len(signature), 20)
if __name__ == "__main__":
unittest.main()