feat: add daily + global notes

This commit is contained in:
2026-07-17 14:43:05 +02:00
parent d2270a737b
commit 0cfe4c7108
7 changed files with 349 additions and 3 deletions
+118
View File
@@ -12,7 +12,9 @@ from pywebpush import WebPushException
from accounts.models import PushSubscription, User
from tracker.models import (
DailyNote,
DoseLog,
GlobalNote,
Medication,
PulseReading,
ReminderSent,
@@ -178,6 +180,74 @@ class PulseApiTests(TrackerTestCase):
self.assertIsNone(stats["trend_bpm_per_day"])
class NoteApiTests(TrackerTestCase):
def test_the_day_includes_its_note(self):
DailyNote.objects.create(body="Ate well.")
response = self.client.get("/api/tracker/day", **self.auth_header())
self.assertEqual(response.json()["note"]["body"], "Ate well.")
def test_saving_a_daily_note_twice_overwrites(self):
for body in ("Sleepy.", "Playful after all."):
response = self.client.post(
"/api/tracker/notes/daily",
{"body": body},
content_type="application/json",
**self.auth_header(),
)
self.assertEqual(response.status_code, 200)
self.assertEqual(DailyNote.objects.count(), 1)
self.assertEqual(DailyNote.objects.get().body, "Playful after all.")
def test_a_daily_note_can_target_a_past_day(self):
yesterday = timezone.localdate() - timedelta(days=1)
self.client.post(
"/api/tracker/notes/daily",
{"body": "Rough night.", "date": yesterday.isoformat()},
content_type="application/json",
**self.auth_header(),
)
self.assertTrue(DailyNote.objects.filter(date=yesterday).exists())
self.assertFalse(DailyNote.objects.filter(date=timezone.localdate()).exists())
def test_an_empty_body_removes_the_daily_note(self):
DailyNote.objects.create(body="Old news.")
self.client.post(
"/api/tracker/notes/daily",
{"body": " "},
content_type="application/json",
**self.auth_header(),
)
self.assertEqual(DailyNote.objects.count(), 0)
def test_the_global_note_exists_without_ever_being_created(self):
response = self.client.get("/api/tracker/notes/global", **self.auth_header())
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["body"], "")
def test_the_global_note_is_shared_and_unique(self):
response = self.client.put(
"/api/tracker/notes/global",
{"body": "Vet on Friday."},
content_type="application/json",
**self.auth_header(),
)
self.assertEqual(response.status_code, 200)
other = User.objects.create_superuser("marie", password="hunter2hunter2")
self.client.force_login(other)
response = self.client.get("/api/tracker/notes/global")
self.assertEqual(response.json()["body"], "Vet on Friday.")
self.assertEqual(GlobalNote.objects.count(), 1)
class TodayPageTests(TrackerTestCase):
def test_the_page_requires_login(self):
response = self.client.get(reverse("tracker:today"))
@@ -229,6 +299,54 @@ class TodayPageTests(TrackerTestCase):
self.assertFalse(PulseReading.objects.filter(date=today).exists())
def test_saving_records_the_daily_note(self):
self.client.force_login(self.user)
today = timezone.localdate()
self.client.post(
reverse("tracker:today"),
{"date": today.isoformat(), "note": "Ate well."},
)
self.assertEqual(DailyNote.objects.get(date=today).body, "Ate well.")
def test_clearing_the_note_field_removes_the_note(self):
self.client.force_login(self.user)
today = timezone.localdate()
DailyNote.objects.create(date=today, body="Old news.")
self.client.post(reverse("tracker:today"), {"date": today.isoformat()})
self.assertFalse(DailyNote.objects.filter(date=today).exists())
def test_the_shared_note_form_saves_without_touching_the_day(self):
self.client.force_login(self.user)
today = timezone.localdate()
response = self.client.post(
reverse("tracker:today"),
{"date": today.isoformat(), "global_note": "Vet on Friday."},
)
self.assertEqual(response.status_code, 302)
self.assertEqual(GlobalNote.load().body, "Vet on Friday.")
# Its own form carries no dose or pulse fields; the day must stay untouched.
self.assertFalse(DoseLog.objects.exists())
self.assertFalse(PulseReading.objects.exists())
self.assertFalse(DailyNote.objects.exists())
def test_the_page_shows_both_notes(self):
self.client.force_login(self.user)
DailyNote.objects.create(body="More playful than yesterday.")
note = GlobalNote.load()
note.body = "Vet on Friday."
note.save()
response = self.client.get(reverse("tracker:today"))
self.assertContains(response, "More playful than yesterday.")
self.assertContains(response, "Vet on Friday.")
def test_the_graph_appears_once_there_are_two_readings(self):
self.client.force_login(self.user)
today = timezone.localdate()