Turn on push from onboarding step 3 and add a test-push endpoint (Feature 19)
CI / ci (push) Successful in 6m59s
CI / ci (pull_request) Successful in 7m2s

Onboarding step 3's "Turn on notifications" now calls usePush().subscribePush
straight from that tap (the only place onboarding asks for permission) and
shows how it ended: on; blocked, with how to allow it in the browser's site
settings; not supported, with how to add MealQuest to the Home Screen on
iPhone; or a dismissed prompt that can be asked again. "Maybe later" still
finishes without asking. The interim notificationsUnavailable is gone.

POST /api/v1/settings/notifications/test-push queues "MealQuest test
notification" through the notification outbox as a plan_ready event with a
fresh plan_ready:test-<ULID> key, opening /plan, on the push channel only
(new notify.Service.EmitPush), never Google Chat. It answers 202
{event_key, subscriptions}, or 409 no_subscriptions / push_off rather than
reporting success when nothing would be sent.

Maestro task f89279b8-b92c-4d9f-a6c2-fd87fccda509.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 16:54:23 -04:00
co-authored by Claude Opus 5.5
parent 51e0213e92
commit 875a0faaae
12 changed files with 505 additions and 139 deletions
+48
View File
@@ -259,6 +259,54 @@ func TestEmitIgnoresDuplicateKey(t *testing.T) {
}
}
func TestEmitPushStoresOnlyAPushRow(t *testing.T) {
ctx := context.Background()
svc, st, _ := newTestService(t)
setPref(t, st, PlanReady, true, true)
const key = "plan_ready:test-1"
if err := svc.EmitPush(ctx, planReady(key)); err != nil {
t.Fatal(err)
}
r := onlyRow(t, st, key, ChannelPush)
if r.Status != "pending" || r.NextAttemptAt.String != timestamp(start) {
t.Errorf("row = %+v, want pending, due now", r)
}
select {
case <-svc.wake:
default:
t.Error("EmitPush did not wake the worker")
}
// The same key again is ignored, as by Emit.
if err := svc.EmitPush(ctx, planReady(key)); err != nil {
t.Fatalf("duplicate EmitPush: %v", err)
}
if got := onlyRow(t, st, key, ChannelPush); got != r {
t.Fatalf("duplicate EmitPush changed the row:\n got %+v\nwant %+v", got, r)
}
}
func TestEmitPushRefusesWhenPushIsOff(t *testing.T) {
svc, st, _ := newTestService(t)
setPref(t, st, PlanReady, false, true)
const key = "plan_ready:test-1"
if err := svc.EmitPush(context.Background(), planReady(key)); !errors.Is(err, ErrPushOff) {
t.Fatalf("EmitPush = %v, want ErrPushOff", err)
}
if rows := outbox(t, st, key); len(rows) != 0 {
t.Fatalf("rows = %v, want none", rows)
}
}
func TestEmitPushRejectsInvalidEvents(t *testing.T) {
svc, _, _ := newTestService(t)
ev := planReady("plan_ready:test-1")
ev.URL = "https://evil.example/plan"
if err := svc.EmitPush(context.Background(), ev); !errors.Is(err, ErrInvalidEvent) {
t.Fatalf("EmitPush = %v, want ErrInvalidEvent", err)
}
}
func TestEmitRejectsInvalidEvents(t *testing.T) {
svc, st, _ := newTestService(t)
valid := planReady("plan_ready:2026-10-12")