Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/app/api/referrals/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ describe("POST /api/referrals", () => {
expect(body.error).toContain("Maximum 20");
});

it("should return 400 when any invite email is not a string", async () => {
mockGetAuthContext.mockResolvedValue({
user: { id: "user1" },
supabase: mockSupabase,
});

const res = await POST(makePostRequest({ emails: ["friend@test.com", 42] }));

expect(res.status).toBe(400);
const body = await res.json();
expect(body.error).toBe("All invite emails must be strings");
expect(mockCreateServiceClient).not.toHaveBeenCalled();
});

it("should create referrals for valid emails", async () => {
mockGetAuthContext.mockResolvedValue({
user: { id: "user1" },
Expand Down
7 changes: 7 additions & 0 deletions src/app/api/referrals/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ export async function POST(request: NextRequest) {
);
}

if (!emails.every((email) => typeof email === "string")) {
return NextResponse.json(
{ error: "All invite emails must be strings" },
{ status: 400 }
);
}

if (emails.length > 20) {
return NextResponse.json(
{ error: "Maximum 20 invites at a time" },
Expand Down
Loading