Merge branch 'bugfix/10-password-reset-tests': Password reset API and form wiring

This commit is contained in:
2026-05-01 18:24:09 -07:00
3 changed files with 67 additions and 18 deletions
+11 -15
View File
@@ -29,6 +29,12 @@ Given('I am on the login page', async function () {
await world.page.waitForLoadState('domcontentloaded'); await world.page.waitForLoadState('domcontentloaded');
}); });
Given('I am on the password reset page', async function () {
console.log('🌍 Navigating to password reset page');
await world.page.goto(`${world.baseURL}/auth/password-reset`);
await world.page.waitForLoadState('domcontentloaded');
});
Given('I am on the {string} page', async function (pageName: string) { Given('I am on the {string} page', async function (pageName: string) {
const pageUrls: Record<string, string> = { const pageUrls: Record<string, string> = {
'home': '/', 'home': '/',
@@ -174,28 +180,18 @@ When('I click the {string} link', async function (linkText: string) {
const selector = `a:has-text("${linkText}")`; const selector = `a:has-text("${linkText}")`;
console.log(`🌍 Clicking link: ${linkText}`); console.log(`🌍 Clicking link: ${linkText}`);
// Get current URL
const currentUrl = world.page.url();
// Click the link // Click the link
await world.page.click(selector); await world.page.click(selector);
// Wait a bit for navigation to start // Wait for navigation to complete
await world.page.waitForTimeout(500);
// Check if URL changed
const newUrl = world.page.url();
if (newUrl === currentUrl) {
console.log(`🌍 URL did not change immediately after link click`);
// Wait for any navigation to complete
try { try {
await world.page.waitForLoadState('domcontentloaded', { timeout: 5000 }); await world.page.waitForLoadState('networkidle', { timeout: 10000 });
} catch { } catch {
console.log(`🌍 DOMContentLoaded not reached, continuing`); console.log(`🌍 Networkidle not reached, continuing`);
} }
} else {
const newUrl = world.page.url();
console.log(`🌍 Page navigated to: ${newUrl}`); console.log(`🌍 Page navigated to: ${newUrl}`);
}
}); });
When('I click the {string} wordmark', async function (wordmarkText: string) { When('I click the {string} wordmark', async function (wordmarkText: string) {
+37
View File
@@ -0,0 +1,37 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
export async function POST(request: Request) {
try {
const body = await request.json();
const { email } = body;
if (!email) {
return NextResponse.json(
{ error: "Email is required" },
{ status: 400 }
);
}
const user = await prisma.user.findUnique({
where: { email: email.toLowerCase() },
});
if (!user) {
return NextResponse.json(
{ error: "If an account exists with that email, a password reset link will be sent" },
{ status: 400 }
);
}
return NextResponse.json({
success: true,
message: "If an account exists with that email, a password reset link will be sent"
});
} catch (error: unknown) {
console.error("Error processing password reset request:", error);
const message =
error instanceof Error ? error.message : "Failed to process password reset request";
return NextResponse.json({ error: message }, { status: 500 });
}
}
+16
View File
@@ -15,6 +15,22 @@ export default function PasswordResetPage() {
setError("") setError("")
try { try {
const response = await fetch("/api/auth/password-reset", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ email }),
})
const data = await response.json()
if (!response.ok) {
setError(data.error || "Failed to send reset link")
setLoading(false)
return
}
setSent(true) setSent(true)
} catch (err) { } catch (err) {
console.error("Password reset error:", err) console.error("Password reset error:", err)