added price drops to alerts/fixed race condition where late claimed docs got their tags wiped and sent to the api without tags
This commit is contained in:
1 parent
03cc3a35cb
commit
0275f94500
2 files changed
+37
-6
No files matched your search
@@ -99,6 +99,32 @@ def test_existing_doc_with_new_price_stamps_false():
|
||||
assert alert_doc(collection)["newListing"] is False
|
||||
|
||||
|
||||
def test_drop_alert_carries_price_before_drop():
|
||||
"""the doc's priceBeforeDrop is cleared by the next no-drop cycle, so the
|
||||
alert keeps its own copy from emit time — a drop claimed late still knows
|
||||
what it dropped from"""
|
||||
|
||||
existing = {"_id": "p1", "currentPrice": 100.0, "pastPrices": []}
|
||||
collection = FakeCollection([existing])
|
||||
run(collection, [_product(current=95.0)])
|
||||
|
||||
assert alert_doc(collection)["priceBeforeDrop"] == 100.0
|
||||
|
||||
|
||||
def test_non_drop_alert_carries_none():
|
||||
"""a never-seen higher price alerts without a drop; discoveries have no
|
||||
prior price at all"""
|
||||
|
||||
existing = {"_id": "p1", "currentPrice": 100.0, "pastPrices": []}
|
||||
collection = FakeCollection([existing])
|
||||
run(collection, [_product(current=120.0)])
|
||||
assert alert_doc(collection)["priceBeforeDrop"] is None
|
||||
|
||||
discovery = FakeCollection()
|
||||
run(discovery, [_product()])
|
||||
assert alert_doc(discovery)["priceBeforeDrop"] is None
|
||||
|
||||
|
||||
def test_existing_doc_with_known_price_emits_no_alert():
|
||||
existing = {
|
||||
"_id": "p1",
|
||||
@@ -112,8 +138,9 @@ def test_existing_doc_with_known_price_emits_no_alert():
|
||||
assert collection.alerts is None
|
||||
|
||||
|
||||
def test_build_alert_defaults_missing_flag_to_false():
|
||||
def test_build_alert_defaults_missing_fields():
|
||||
"""Direct callers passing an unstamped document must not KeyError."""
|
||||
|
||||
alert = build_alert("bestbuy", {"_id": "p1"}, NOW)
|
||||
assert alert["newListing"] is False
|
||||
assert alert["priceBeforeDrop"] is None
|
||||
Reference in new issue
Block a user