From e4b095f7cca7ea33f68822ad647fd42c699add51 Mon Sep 17 00:00:00 2001 From: Taleef7 Date: Wed, 8 Apr 2026 01:31:00 -0400 Subject: [PATCH 1/2] fix: harden launch readiness and lifecycle coverage --- app/admin/actions.ts | 15 +- app/admin/matches/[id]/MatchActions.tsx | 12 +- app/admin/matches/[id]/page.tsx | 12 + app/admin/requests/[id]/AssignTutorForm.tsx | 12 +- app/admin/requests/actions.ts | 10 +- app/admin/sessions/SessionFilters.tsx | 10 +- app/admin/sessions/page.tsx | 8 +- app/admin/users/page.tsx | 16 +- app/auth/callback/route.ts | 44 +- app/auth/sign-in/SignInForm.tsx | 11 +- app/auth/sign-up/page.tsx | 10 +- app/auth/verify/page.tsx | 5 +- app/dashboard/layout.tsx | 3 +- app/dashboard/page.tsx | 3 +- e2e/auth.spec.ts | 36 ++ e2e/fixtures/payment-proof.pdf | Bin 0 -> 340 bytes e2e/lifecycle.spec.ts | 388 ++++++++++++++++++ lib/__tests__/auth-utils.test.ts | 80 ++++ lib/admin/__tests__/sessions.test.ts | 28 ++ lib/admin/__tests__/users.test.ts | 34 ++ lib/admin/sessions.ts | 32 ++ lib/admin/users.ts | 58 +++ lib/auth/utils.ts | 58 +++ .../session-status-transitions.test.ts | 25 ++ lib/services/session-status-transitions.ts | 15 + lib/services/sessions.ts | 13 + next-env.d.ts | 2 +- package-lock.json | 28 +- 28 files changed, 883 insertions(+), 85 deletions(-) create mode 100644 e2e/fixtures/payment-proof.pdf create mode 100644 e2e/lifecycle.spec.ts create mode 100644 lib/__tests__/auth-utils.test.ts create mode 100644 lib/admin/__tests__/sessions.test.ts create mode 100644 lib/admin/__tests__/users.test.ts create mode 100644 lib/admin/sessions.ts create mode 100644 lib/admin/users.ts diff --git a/app/admin/actions.ts b/app/admin/actions.ts index 84d624d..3e975f8 100644 --- a/app/admin/actions.ts +++ b/app/admin/actions.ts @@ -7,6 +7,7 @@ import { createAdminClient } from "@/lib/supabase/admin"; import { requireAdmin } from "@/lib/auth/requireAdmin"; import { revalidatePath } from "next/cache"; import { z } from "zod"; +import { buildAdminUpdateUserProfileAuditEntry } from "@/lib/admin/users"; const VALID_ROLES = ["student", "parent", "tutor", "admin"] as const; type Role = (typeof VALID_ROLES)[number]; @@ -98,7 +99,7 @@ const updateProfileSchema = z.object({ /** Update a user's display name and WhatsApp number. */ export async function updateUserProfile(userId: string, formData: FormData) { - await requireAdmin(); + const adminUserId = await requireAdmin(); const raw = { display_name: formData.get("display_name") as string, @@ -122,13 +123,11 @@ export async function updateUserProfile(userId: string, formData: FormData) { if (error) throw new Error(`Failed to update profile: ${error.message}`); await admin.from("audit_logs").insert([ - { - actor_user_id: userId, - action: "admin_update_user_profile", - entity_type: "user_profiles", - entity_id: userId, - details: { display_name: parsed.data.display_name }, - }, + buildAdminUpdateUserProfileAuditEntry({ + actorUserId: adminUserId, + targetUserId: userId, + displayName: parsed.data.display_name, + }), ]); revalidatePath("/admin/users"); diff --git a/app/admin/matches/[id]/MatchActions.tsx b/app/admin/matches/[id]/MatchActions.tsx index 20b4a51..fd97ab9 100644 --- a/app/admin/matches/[id]/MatchActions.tsx +++ b/app/admin/matches/[id]/MatchActions.tsx @@ -260,10 +260,11 @@ export function EditMatchForm({
-