mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
Merge commit 'ca66b39b7ee36803864142c954b7f0ca0afbb7ac' into codex/arch/config-database-worker
This commit is contained in:
@@ -40,6 +40,34 @@ def test_subscription_and_outbox_intent_commit_together() -> None:
|
||||
assert report_intent.event_key.endswith(":report")
|
||||
|
||||
|
||||
def test_subscription_notification_snapshot_is_part_of_same_transaction() -> None:
|
||||
"""订阅新增通知快照与事件、统计意图一起暂存,便于崩溃恢复。"""
|
||||
calls = []
|
||||
repository = MagicMock()
|
||||
repository.stage_add.side_effect = lambda *_args: calls.append("subscription") or _Staged()
|
||||
outbox = MagicMock()
|
||||
outbox.stage.side_effect = lambda *_args: calls.append("outbox")
|
||||
unit_of_work = MagicMock()
|
||||
unit_of_work.commit.side_effect = lambda: calls.append("commit")
|
||||
command = CreateSubscriptionCommand(repository, unit_of_work, outbox=outbox)
|
||||
|
||||
command.execute(
|
||||
{},
|
||||
{"name": "demo"},
|
||||
"user",
|
||||
notification={"title": "订阅成功", "text": "demo"},
|
||||
)
|
||||
|
||||
intents = [call.args[0] for call in outbox.stage.call_args_list]
|
||||
assert [intent.topic for intent in intents] == [
|
||||
"subscribe.added",
|
||||
"subscribe.added.notification",
|
||||
"subscribe.added.report",
|
||||
]
|
||||
assert intents[1].payload["message"]["text"] == "demo"
|
||||
assert calls[-1] == "commit"
|
||||
|
||||
|
||||
def test_outbox_stage_failure_rolls_back_business_transaction() -> None:
|
||||
"""intent 无法持久化时订阅行不得单独提交。"""
|
||||
repository = MagicMock()
|
||||
|
||||
@@ -139,3 +139,28 @@ def test_completion_success_closes_event_then_report_intent():
|
||||
]
|
||||
assert calls[6][1]["idempotency_key"] == calls[2][1].event_key
|
||||
assert calls[8][1]["idempotency_key"] == calls[3][1].event_key
|
||||
|
||||
|
||||
def test_completion_stages_and_closes_notification_snapshot() -> None:
|
||||
"""完成通知快照与业务事务同提交,成功即时投递后独立收口。"""
|
||||
calls = []
|
||||
command, notify, report = _command(calls)
|
||||
|
||||
command.execute(
|
||||
7,
|
||||
{"id": 7, "media_source": "tmdb", "media_id": "123", "season": 2},
|
||||
{"title": "Test"},
|
||||
notify=notify,
|
||||
report=report,
|
||||
notification={"title": "完成", "text": "Test"},
|
||||
)
|
||||
|
||||
staged = [call[1] for call in calls if call[0] == "stage"]
|
||||
assert [intent.topic for intent in staged] == [
|
||||
"subscribe.complete",
|
||||
"subscribe.complete.notification",
|
||||
"subscribe.complete.report",
|
||||
]
|
||||
assert staged[1].payload["message"]["title"] == "完成"
|
||||
completed = [call[1] for call in calls if call[0] == "complete"]
|
||||
assert completed[0].endswith(":notification")
|
||||
|
||||
Reference in New Issue
Block a user