Allow recording zero eggs collected
All checks were successful
Deploy / deploy (push) Successful in 1m37s

Enable recording "checked coop, found 0 eggs" to distinguish from days
when the coop wasn't checked at all. Statistics remain eggs/calendar day.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-09 06:37:31 +00:00
parent d91ee362fa
commit eee8552345
5 changed files with 34 additions and 12 deletions

View File

@@ -285,15 +285,27 @@ class TestProductPayloads:
)
assert payload.quantity == 12
def test_quantity_must_be_positive(self):
"""quantity must be >= 1."""
def test_quantity_zero_is_valid(self):
"""quantity=0 is valid (checked but found none)."""
from animaltrack.events.payloads import ProductCollectedPayload
payload = ProductCollectedPayload(
location_id="01ARZ3NDEKTSV4RRFFQ69G5FAV",
product_code="egg.duck",
quantity=0,
resolved_ids=["01ARZ3NDEKTSV4RRFFQ69G5FAV"],
)
assert payload.quantity == 0
def test_quantity_cannot_be_negative(self):
"""quantity must be >= 0."""
from animaltrack.events.payloads import ProductCollectedPayload
with pytest.raises(ValidationError):
ProductCollectedPayload(
location_id="01ARZ3NDEKTSV4RRFFQ69G5FAV",
product_code="egg.duck",
quantity=0,
quantity=-1,
resolved_ids=["01ARZ3NDEKTSV4RRFFQ69G5FAV"],
)

View File

@@ -137,10 +137,10 @@ class TestEggCollection:
assert event_row is not None
assert event_row[0] == "ProductCollected"
def test_egg_collection_validation_quantity_zero(
self, client, location_strip1_id, ducks_at_strip1
def test_egg_collection_quantity_zero_accepted(
self, client, seeded_db, location_strip1_id, ducks_at_strip1
):
"""quantity=0 returns 422."""
"""quantity=0 is accepted (checked coop, found no eggs)."""
resp = client.post(
"/actions/product-collected",
data={
@@ -150,7 +150,17 @@ class TestEggCollection:
},
)
assert resp.status_code == 422
assert resp.status_code in [200, 302, 303]
# Verify event was created with quantity=0
event_row = seeded_db.execute(
"SELECT payload FROM events WHERE type = 'ProductCollected' ORDER BY id DESC LIMIT 1"
).fetchone()
assert event_row is not None
import json
payload = json.loads(event_row[0])
assert payload["quantity"] == 0
def test_egg_collection_validation_quantity_negative(
self, client, location_strip1_id, ducks_at_strip1