-
Notifications
You must be signed in to change notification settings - Fork 49
Validate affiliate offer edit text fields #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ import { NextRequest, NextResponse } from "next/server"; | |
| import { getAuthContext } from "@/lib/auth/get-user"; | ||
| import { createServiceClient } from "@/lib/supabase/service"; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| type AnySupabase = any; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The |
||
| import { validateOfferInput } from "@/lib/affiliates/validation"; | ||
|
|
||
|
|
@@ -100,8 +99,18 @@ export async function PATCH( | |
| // Partial validation — only validate provided fields | ||
| const updateData: Record<string, unknown> = { updated_at: new Date().toISOString() }; | ||
|
|
||
| if (body.title !== undefined) updateData.title = body.title.trim(); | ||
| if (body.description !== undefined) updateData.description = body.description.trim(); | ||
| if (body.title !== undefined) { | ||
| if (typeof body.title !== "string") { | ||
| return NextResponse.json({ error: "title must be a string" }, { status: 400 }); | ||
| } | ||
| updateData.title = body.title.trim(); | ||
| } | ||
| if (body.description !== undefined) { | ||
| if (typeof body.description !== "string") { | ||
| return NextResponse.json({ error: "description must be a string" }, { status: 400 }); | ||
| } | ||
| updateData.description = body.description.trim(); | ||
| } | ||
| if (body.product_url !== undefined) updateData.product_url = body.product_url; | ||
| if (body.product_type !== undefined) updateData.product_type = body.product_type; | ||
| if (body.price_sats !== undefined) updateData.price_sats = body.price_sats; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two new tests only exercise rejection (400) scenarios. There is no test that verifies a valid string
titleordescriptionactually flows through to a DB update and returns 200. If the update logic were accidentally broken (e.g.,updateDataconstruction or the.update()call), both existing tests would still pass, leaving the regression undetected.