fix: prejoin fansclub before reservation
This commit is contained in:
1 parent
f95832579a
commit
ba9ac4cb0e
6 files changed
+300
-17
No files matched your search
@@ -50,6 +50,42 @@ def test_high_value_countdown_gt_records_reservation_and_returns_true():
|
||||
analyser.swipe_up_to_next_live.assert_called_once()
|
||||
|
||||
|
||||
def test_high_value_reservation_prejoins_fansclub_before_recording():
|
||||
analyser = _mk_analyser()
|
||||
analyser.auto_join_fansclub = True
|
||||
analyser.button_text_raw = "加入购物粉丝团并关注主播"
|
||||
future_ts = time.time() + 300
|
||||
detail = ("高价值福袋", "05:00", 10, 1, 1999.0, (time.time(), future_ts, 300))
|
||||
events = []
|
||||
|
||||
def _fake_prejoin(_analyser, _button_text):
|
||||
events.append("prejoin")
|
||||
return True
|
||||
|
||||
def _fake_record(**_kwargs):
|
||||
events.append("record")
|
||||
return False
|
||||
|
||||
with patch(
|
||||
"douyin.fudai.core.fudai_filter_pkg.join_decision.should_skip_fudai_by_config",
|
||||
return_value=(True, "countdown_gt_118"),
|
||||
), patch(
|
||||
"douyin.fudai.core.fudai_attend_pkg.fansclub_handler.handle_fansclub_branch",
|
||||
side_effect=_fake_prejoin,
|
||||
) as mock_prejoin, patch(
|
||||
"douyin.reservation.reservation_logic.record.record_high_value_reservation",
|
||||
side_effect=_fake_record,
|
||||
) as mock_record:
|
||||
ok = basic_join_decision(analyser, detail)
|
||||
|
||||
assert ok is True
|
||||
assert events == ["prejoin", "record"]
|
||||
mock_prejoin.assert_called_once_with(analyser, "加入购物粉丝团并关注主播")
|
||||
mock_record.assert_called_once()
|
||||
assert analyser._reservation_prejoined_fansclub is True
|
||||
analyser.swipe_up_to_next_live.assert_called_once()
|
||||
|
||||
|
||||
def test_high_value_countdown_within_join_window_attends():
|
||||
analyser = _mk_analyser()
|
||||
future_ts = time.time() + 30 # <= join_ahead_seconds
|
||||
|
||||
@@ -45,3 +45,123 @@ def test_record_high_value_reservation_preserves_button_fields():
|
||||
assert ok is False
|
||||
assert reservations[0]["button_text"] == "一键发表评论"
|
||||
assert reservations[0]["button_status"] == "需要评论"
|
||||
|
||||
|
||||
def test_record_high_value_reservation_preserves_prejoined_fansclub_marker():
|
||||
from douyin.reservation.reservation_logic.record import record_high_value_reservation
|
||||
|
||||
analyser = SimpleNamespace(
|
||||
_log_kv=MagicMock(return_value=None),
|
||||
_fudai_button_text="加入购物粉丝团并关注主播",
|
||||
_fudai_button_status="需要加入粉丝团",
|
||||
_reservation_prejoined_fansclub=True,
|
||||
_reservation_prejoin_fansclub_button_text="加入购物粉丝团并关注主播",
|
||||
_reservation_prejoin_fansclub_ts=123.0,
|
||||
)
|
||||
reservations = []
|
||||
|
||||
ok = record_high_value_reservation(
|
||||
analyser=analyser,
|
||||
fudai_content_text="高价值福袋",
|
||||
prize_value_yuan=159.0,
|
||||
lastsecond=200,
|
||||
future_timestamp=time.time() + 600,
|
||||
x=162,
|
||||
needswitch=True,
|
||||
wait_minutes=0,
|
||||
post_switch_delay_s=0.0,
|
||||
room_pos=5,
|
||||
reservations=reservations,
|
||||
reservation_focus_until_ts_ref=[0.0],
|
||||
close_detail_callback=lambda: None,
|
||||
swipe_up_switch_callback=lambda: None,
|
||||
swipe_down_back_callback=lambda: None,
|
||||
add_reservation_callback=lambda items, item: items.append(item),
|
||||
sort_reservations_callback=lambda: None,
|
||||
write_state_callback=lambda: None,
|
||||
room_title="交个朋友",
|
||||
room_title_raw="交个朋友",
|
||||
task_count=2,
|
||||
time_text="03:21",
|
||||
participants=0,
|
||||
copies=1,
|
||||
)
|
||||
|
||||
assert ok is False
|
||||
assert reservations[0]["prejoined_fansclub_before_reservation"] is True
|
||||
assert reservations[0]["prejoin_fansclub_button_text"] == "加入购物粉丝团并关注主播"
|
||||
assert reservations[0]["prejoin_fansclub_ts"] == 123.0
|
||||
|
||||
|
||||
def test_write_reservations_state_preserves_prejoined_fansclub_marker(tmp_path):
|
||||
from douyin.reservation.douyin_reservation import write_reservations_state
|
||||
|
||||
state_path = tmp_path / "reservations.json"
|
||||
write_reservations_state(
|
||||
state_path=str(state_path),
|
||||
reservations=[
|
||||
{
|
||||
"future_ts": time.time() + 600,
|
||||
"prize_value_yuan": 159.0,
|
||||
"content": "高价值福袋",
|
||||
"pos_seen": 5,
|
||||
"room_title": "交个朋友",
|
||||
"room_title_raw": "交个朋友",
|
||||
"task_count": 2,
|
||||
"button_text": "加入购物粉丝团并关注主播",
|
||||
"button_status": "需要加入粉丝团",
|
||||
"prejoined_fansclub_before_reservation": True,
|
||||
"prejoin_fansclub_button_text": "加入购物粉丝团并关注主播",
|
||||
"prejoin_fansclub_ts": 123.0,
|
||||
}
|
||||
],
|
||||
room_pos=5,
|
||||
current_room_title="交个朋友",
|
||||
current_room_title_raw="交个朋友",
|
||||
reason="test",
|
||||
)
|
||||
|
||||
import json
|
||||
|
||||
data = json.loads(state_path.read_text(encoding="utf-8"))
|
||||
item = data["reservations"][0]
|
||||
assert item["prejoined_fansclub_before_reservation"] is True
|
||||
assert item["prejoin_fansclub_button_text"] == "加入购物粉丝团并关注主播"
|
||||
assert item["prejoin_fansclub_ts"] == 123.0
|
||||
|
||||
|
||||
def test_duplicate_reservation_preserves_prejoined_fansclub_marker():
|
||||
from douyin.reservation.reservation_logic.add import add_reservation_core_logic
|
||||
|
||||
ft = time.time() + 600
|
||||
reservations = [
|
||||
{
|
||||
"future_ts": ft,
|
||||
"prize_value_yuan": 159.0,
|
||||
"content": "高价值福袋",
|
||||
"room_title": "交个朋友",
|
||||
}
|
||||
]
|
||||
item = {
|
||||
"future_ts": ft,
|
||||
"prize_value_yuan": 159.0,
|
||||
"content": "高价值福袋",
|
||||
"room_title": "交个朋友",
|
||||
"prejoined_fansclub_before_reservation": True,
|
||||
"prejoin_fansclub_button_text": "加入购物粉丝团并关注主播",
|
||||
"prejoin_fansclub_ts": 123.0,
|
||||
}
|
||||
|
||||
ok = add_reservation_core_logic(
|
||||
reservations=reservations,
|
||||
item=item,
|
||||
max_reservations=10,
|
||||
analyser=SimpleNamespace(_log_kv=MagicMock(return_value=None)),
|
||||
write_state_callback=lambda: None,
|
||||
)
|
||||
|
||||
assert ok is False
|
||||
assert len(reservations) == 1
|
||||
assert reservations[0]["prejoined_fansclub_before_reservation"] is True
|
||||
assert reservations[0]["prejoin_fansclub_button_text"] == "加入购物粉丝团并关注主播"
|
||||
assert reservations[0]["prejoin_fansclub_ts"] == 123.0
|
||||
Reference in new issue
Block a user