fix: add vapid diagnostics

This commit is contained in:
2026-07-14 21:25:26 +02:00
parent 5198826f83
commit f783794b86
4 changed files with 158 additions and 16 deletions
+28
View File
@@ -259,6 +259,34 @@ class PwaTests(TrackerTestCase):
self.assertContains(response, 'rel="manifest"')
self.assertContains(response, "serviceWorker.register")
@override_settings(VAPID_PUBLIC_KEY="", VAPID_PRIVATE_KEY="")
def test_the_reminder_card_explains_itself_when_keys_are_missing(self):
# It used to hide entirely, which is indistinguishable from a broken page.
self.client.force_login(self.user)
response = self.client.get(reverse("tracker:today"))
self.assertContains(response, "Reminders")
self.assertContains(response, "Diagnostics")
self.assertContains(response, "generate_vapid_keys")
@override_settings(VAPID_PUBLIC_KEY="BMn-test-public-key")
def test_the_diagnostics_report_reminder_times_and_devices(self):
self.client.force_login(self.user)
response = self.client.get(reverse("tracker:today"))
self.assertContains(response, "Doses with a reminder time: 0 of 3")
self.assertContains(response, "Devices subscribed (this account): 0")
self.morning.reminder_time = "08:00"
self.morning.save()
PushSubscription.objects.create(
user=self.user, endpoint="https://push.example/a", p256dh="k", auth="s"
)
response = self.client.get(reverse("tracker:today"))
self.assertContains(response, "Doses with a reminder time: 1 of 3")
self.assertContains(response, "Devices subscribed (this account): 1")
def test_the_manifest_is_valid_json_pointing_at_real_icons(self):
response = self.client.get(reverse("manifest"))
+8 -1
View File
@@ -104,7 +104,14 @@ def today(request):
"next_date": day + timedelta(days=1),
"chart": build_chart(readings),
"reading_count": len(readings),
# Empty when push is not configured; the page then hides the card.
# Empty when push is not configured; the card then says so rather than
# vanishing, because a missing card looks like a bug in the page.
"vapid_public_key": settings.VAPID_PUBLIC_KEY,
"doses_with_reminders": ScheduledDose.objects.filter(
is_active=True,
medication__is_active=True,
reminder_time__isnull=False,
).count(),
"subscribed_devices": request.user.push_subscriptions.count(),
},
)