完善设备端体验与微信校验支持
This commit is contained in:
@@ -175,6 +175,7 @@ async def test_resolve_notification_link_returns_chat_detail_params(monkeypatch)
|
||||
def first(self):
|
||||
return {
|
||||
"conversation_id": 6,
|
||||
"message_id": 209,
|
||||
"child_id": 8,
|
||||
"child_name": "小明",
|
||||
"device_id": "TalkingQ_XQSN00001007",
|
||||
@@ -186,6 +187,7 @@ async def test_resolve_notification_link_returns_chat_detail_params(monkeypatch)
|
||||
assert params["conversation_id"] == 6
|
||||
assert params["child_id"] == 8
|
||||
assert params["user_id"] == 4
|
||||
assert params["device_id"] == "TalkingQ_XQSN00001007"
|
||||
return FakeResult()
|
||||
|
||||
async def close(self):
|
||||
@@ -231,10 +233,89 @@ async def test_resolve_notification_link_rejects_other_user(monkeypatch):
|
||||
}
|
||||
)
|
||||
|
||||
class FakeResult:
|
||||
def mappings(self):
|
||||
return self
|
||||
|
||||
def first(self):
|
||||
return None
|
||||
|
||||
class FakeSession:
|
||||
async def execute(self, sql, params):
|
||||
assert params["message_id"] == 209
|
||||
assert params["conversation_id"] == 6
|
||||
assert params["child_id"] == 8
|
||||
assert params["user_id"] == 5
|
||||
return FakeResult()
|
||||
|
||||
async def close(self):
|
||||
pass
|
||||
|
||||
async def fake_get_session():
|
||||
return FakeSession()
|
||||
|
||||
monkeypatch.setattr(service, "get_session", fake_get_session)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
await service.resolve_notification_link(token=token, user_id=5)
|
||||
|
||||
assert exc_info.value.status_code == 403
|
||||
assert exc_info.value.status_code == 404
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_notification_link_redirects_to_current_family_member_message(monkeypatch):
|
||||
configure_enabled_wechat_mp(monkeypatch)
|
||||
service = WechatMpNotificationService()
|
||||
token = service._create_notification_token(
|
||||
{
|
||||
"type": "leave_message",
|
||||
"user_id": 4,
|
||||
"conversation_id": 6,
|
||||
"message_id": 209,
|
||||
"child_id": 8,
|
||||
"child_name": "小明",
|
||||
"device_id": "TalkingQ_XQSN00001007",
|
||||
}
|
||||
)
|
||||
|
||||
class FakeResult:
|
||||
def mappings(self):
|
||||
return self
|
||||
|
||||
def first(self):
|
||||
return {
|
||||
"conversation_id": 22,
|
||||
"message_id": 216,
|
||||
"child_id": 8,
|
||||
"child_name": "小明",
|
||||
"device_id": "TalkingQ_XQSN00001007",
|
||||
}
|
||||
|
||||
class FakeSession:
|
||||
async def execute(self, sql, params):
|
||||
assert params["message_id"] == 209
|
||||
assert params["conversation_id"] == 6
|
||||
assert params["child_id"] == 8
|
||||
assert params["user_id"] == 3
|
||||
assert params["user_id_str"] == "3"
|
||||
assert params["device_id"] == "TalkingQ_XQSN00001007"
|
||||
return FakeResult()
|
||||
|
||||
async def close(self):
|
||||
pass
|
||||
|
||||
async def fake_get_session():
|
||||
return FakeSession()
|
||||
|
||||
monkeypatch.setattr(service, "get_session", fake_get_session)
|
||||
|
||||
result = await service.resolve_notification_link(token=token, user_id=3)
|
||||
|
||||
assert result["route"] == "pages/chat/detail/index"
|
||||
assert result["params"]["id"] == 22
|
||||
assert result["params"]["parentUserId"] == 3
|
||||
assert result["params"]["peerId"] == "3"
|
||||
assert result["params"]["messageId"] == 216
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user