food diary bug fix, blocking calorie count

This commit is contained in:
Joren de Graaf
2026-10-18 00:03:47 +02:00
parent e3b14d6823
commit a8418cdba7
8 changed files with 150 additions and 41 deletions
+14
View File
@@ -39,6 +39,20 @@ class FoodApiTests(TestCase):
data = json.dumps(data)
return getattr(self.client, method)(path, data=data, **args)
def test_today_reports_quantity_scaled_known_subtotals_and_missing_fields(self):
day = timezone.localdate()
FoodLogEntry.objects.create(user=self.a, date=day, meal='lunch',
product_name_snapshot='Known lunch', amount=Decimal('100'), quantity=Decimal('2'),
unit='g', calories_kcal=Decimal('120'), protein_g=Decimal('5'))
FoodLogEntry.objects.create(user=self.a, date=day, meal='dinner',
product_name_snapshot='Unknown dinner', amount=Decimal('100'), unit='g')
result = self.call('get', '/api/v1/food/today/').json()
self.assertEqual(Decimal(result['totals']['calories_kcal']), Decimal('240'))
self.assertEqual(Decimal(result['totals']['protein_g']), Decimal('10'))
self.assertTrue(result['incomplete']['calories_kcal'])
self.assertTrue(result['incomplete']['protein_g'])
self.assertIsNone(result['totals']['fat_g'])
def test_atomic_food_log_and_inventory_keeps_historical_snapshot(self):
old = FoodLogEntry.objects.create(user=self.a, product=self.product_a,
date=timezone.localdate() - timedelta(days=1), meal='dinner',