Files
F-r-ldraledigplannerare/backend/tests/unit/test_tip_predicates_hash.py
T
jacobh2 fdbfb7d580 Give tips a date, a scope per child, and a dismissal that sticks
Three faults, all invisible while the tests passed. Advice was built for the
first child only, so a second child got none. The planned days feeding every
count were fetched once per parent and appended to one list, so a couple's
days were counted twice and every intensity and projection derived from them
was wrong. And dismissing a tip forgot the moment the page reloaded.

Tips now carry the date they concern, lifted from figures the rules already
computed, so a view of a month can show only what applies to it. They are
built per child and identified per child, so the same rule firing for two
children is two separate pieces of advice.

A dismissal is stored against a fingerprint of the facts that were dismissed.
When those facts change the advice returns with its new numbers, rather than
one click silencing a warning about a forfeiture that keeps growing.
2026-09-17 22:32:03 +02:00

31 lines
1.2 KiB
Python

"""Tests for `hash_tip_data` — the dismissal-expiry fingerprint.
See `app.entities.tip_dismissal.TipDismissal` and
`TipsService._drop_stale_dismissed`: a dismissal only stays silent while the
rule's `data` still hashes the same. These tests pin the two properties that
matter for that contract: stability (same data → same hash, regardless of
key order) and sensitivity (any value change → a different hash).
"""
from app.utils.tip_predicates import hash_tip_data
class TestHashTipData:
def test_stable_regardless_of_key_order(self) -> None:
a = hash_tip_data({"parent_name": "Alice", "expiring_days": 12})
b = hash_tip_data({"expiring_days": 12, "parent_name": "Alice"})
assert a == b
def test_changes_when_a_value_changes(self) -> None:
a = hash_tip_data({"parent_name": "Alice", "expiring_days": 12})
b = hash_tip_data({"parent_name": "Alice", "expiring_days": 13})
assert a != b
def test_changes_when_a_key_is_added_or_removed(self) -> None:
a = hash_tip_data({"parent_name": "Alice"})
b = hash_tip_data({"parent_name": "Alice", "expiring_days": 12})
assert a != b
def test_empty_data_hashes_consistently(self) -> None:
assert hash_tip_data({}) == hash_tip_data({})