fix: pick best targeted momo offer per pchome item
All checks were successful
CD Pipeline / deploy (push) Successful in 1m4s
All checks were successful
CD Pipeline / deploy (push) Successful in 1m4s
This commit is contained in:
@@ -361,6 +361,74 @@ def test_sync_targeted_momo_candidates_skips_total_price_identity_review(monkeyp
|
||||
assert count == 0
|
||||
|
||||
|
||||
def test_sync_targeted_momo_candidates_keeps_best_unit_quantity_match(monkeypatch):
|
||||
from services import external_market_offer_service as service
|
||||
|
||||
monkeypatch.setattr(service, "mark_pchome_growth_cache_stale", lambda: None)
|
||||
|
||||
engine = create_engine("sqlite:///:memory:")
|
||||
_seed_external_offer_sync_tables(engine)
|
||||
|
||||
payload = service.sync_targeted_momo_candidates_to_external_offers(engine, [
|
||||
{
|
||||
"product_id": "MOMO-SINGLE",
|
||||
"name": "雪之上 全效合一水凝霜 80g/瓶",
|
||||
"price": 1380,
|
||||
"target_pchome_product_id": "PCH-YUKINOUE",
|
||||
"target_pchome_name": "雪之上 全效合一水凝霜 80g 3入組",
|
||||
"target_pchome_price": 2960,
|
||||
"target_match_score": 0.74,
|
||||
"auto_compare_type": "unit_price",
|
||||
"target_price_basis": "unit_price",
|
||||
"target_match_reasons": ["count_conflict", "unit_comparable"],
|
||||
"target_comparison_mode": "unit_comparable",
|
||||
"target_unit_price_comparison": {
|
||||
"comparable": True,
|
||||
"unit_label": "g",
|
||||
"momo_total_quantity": 80,
|
||||
"competitor_total_quantity": 240,
|
||||
"momo_unit_price": 17.25,
|
||||
"competitor_unit_price": 12.33,
|
||||
"unit_gap_pct": 39.86,
|
||||
},
|
||||
},
|
||||
{
|
||||
"product_id": "MOMO-THREE",
|
||||
"name": "雪之上 全效合一水凝霜 80g X 3入瓶裝",
|
||||
"price": 2680,
|
||||
"target_pchome_product_id": "PCH-YUKINOUE",
|
||||
"target_pchome_name": "雪之上 全效合一水凝霜 80g 3入組",
|
||||
"target_pchome_price": 2960,
|
||||
"target_match_score": 0.74,
|
||||
"auto_compare_type": "unit_price",
|
||||
"target_price_basis": "unit_price",
|
||||
"target_match_reasons": ["unit_comparable"],
|
||||
"target_comparison_mode": "unit_comparable",
|
||||
"target_unit_price_comparison": {
|
||||
"comparable": True,
|
||||
"unit_label": "g",
|
||||
"momo_total_quantity": 240,
|
||||
"competitor_total_quantity": 240,
|
||||
"momo_unit_price": 11.17,
|
||||
"competitor_unit_price": 12.33,
|
||||
"unit_gap_pct": -9.46,
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
assert payload["success"] is True
|
||||
assert payload["candidate_count"] == 2
|
||||
assert payload["written_count"] == 1
|
||||
with engine.connect() as conn:
|
||||
row = conn.execute(text("""
|
||||
SELECT source_product_id, raw_payload_json
|
||||
FROM external_offers
|
||||
""")).mappings().one()
|
||||
raw_payload = __import__("json").loads(row["raw_payload_json"])
|
||||
assert row["source_product_id"] == "MOMO-THREE"
|
||||
assert raw_payload["unit_price_comparison"]["momo_total_quantity"] == 240
|
||||
|
||||
|
||||
def test_external_source_readiness_uses_legacy_momo_reference_cache():
|
||||
from services.external_market_offer_service import build_external_source_readiness
|
||||
|
||||
|
||||
Reference in New Issue
Block a user