Fix egg sale form: remove duplicate route, change price to euros
All checks were successful
Deploy / deploy (push) Successful in 2m50s
All checks were successful
Deploy / deploy (push) Successful in 2m50s
The egg sale form had two issues: - Duplicate POST /actions/product-sold route in products.py was overwriting the eggs.py handler, causing incomplete page responses (no tabs, no recent sales list) - Price input used cents while feed purchase uses euros, inconsistent UX Changes: - Remove duplicate handler from products.py (keep only redirect) - Change sell form price input from cents to euros (consistent with feed) - Parse euros in handler, convert to cents for storage - Add TestEggSale class with 4 tests for the fixed behavior Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -365,3 +365,66 @@ class TestEggCollectionAnimalFiltering:
|
||||
"Juvenile should NOT be associated with egg collection"
|
||||
)
|
||||
assert len(associated_ids) == 1, "Only adult females should be associated"
|
||||
|
||||
|
||||
class TestEggSale:
|
||||
"""Tests for POST /actions/product-sold from eggs page."""
|
||||
|
||||
def test_sell_form_accepts_euros(self, client, seeded_db):
|
||||
"""Price input should accept decimal euros like feed purchase."""
|
||||
resp = client.post(
|
||||
"/actions/product-sold",
|
||||
data={
|
||||
"product_code": "egg.duck",
|
||||
"quantity": "10",
|
||||
"total_price_euros": "12.50", # Euros, not cents
|
||||
"nonce": "test-nonce-sell-euros-1",
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
|
||||
# Event should store 1250 cents
|
||||
import json
|
||||
|
||||
event_row = seeded_db.execute(
|
||||
"SELECT entity_refs FROM events WHERE type = 'ProductSold' ORDER BY id DESC LIMIT 1"
|
||||
).fetchone()
|
||||
entity_refs = json.loads(event_row[0])
|
||||
assert entity_refs["total_price_cents"] == 1250
|
||||
|
||||
def test_sell_response_includes_tabs(self, client, seeded_db):
|
||||
"""After recording sale, response should include full page with tabs."""
|
||||
resp = client.post(
|
||||
"/actions/product-sold",
|
||||
data={
|
||||
"product_code": "egg.duck",
|
||||
"quantity": "10",
|
||||
"total_price_euros": "15.00",
|
||||
"nonce": "test-nonce-sell-tabs-1",
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
# Should have both tabs (proving it's the full eggs page)
|
||||
assert "Harvest" in resp.text
|
||||
assert "Sell" in resp.text
|
||||
|
||||
def test_sell_response_includes_recent_sales(self, client, seeded_db):
|
||||
"""After recording sale, response should include recent sales section."""
|
||||
resp = client.post(
|
||||
"/actions/product-sold",
|
||||
data={
|
||||
"product_code": "egg.duck",
|
||||
"quantity": "10",
|
||||
"total_price_euros": "15.00",
|
||||
"nonce": "test-nonce-sell-recent-1",
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert "Recent Sales" in resp.text
|
||||
|
||||
def test_sell_form_has_euros_field(self, client):
|
||||
"""Sell form should have total_price_euros field, not total_price_cents."""
|
||||
resp = client.get("/?tab=sell")
|
||||
assert resp.status_code == 200
|
||||
assert 'name="total_price_euros"' in resp.text
|
||||
assert "Total Price" in resp.text
|
||||
|
||||
Reference in New Issue
Block a user