Bug
Two test cases in src/app/api/referrals/route.test.ts have expectations that don't match the current implementation in src/app/api/referrals/route.ts.
Bug 1 — Wrong success message expectation
Test (should create referrals for valid emails):
expect(body.message).toContain("1 invite(s) created and sent");
Actual code returns:
"1 invite(s) sent successfully"
The string "created and sent" never appears in the route's response.
Bug 2 — Wrong status code when all emails fail to deliver
Test (should keep created invites when email delivery fails):
expect(res.status).toBe(200);
expect(body.message).toContain("1 email(s) failed to send");
Actual code — when successfulEmails.length === 0 (all delivery failed):
return NextResponse.json(
{ error: "Failed to send invitation emails. Please try again." },
{ status: 502 }
);
The route returns 502, not 200. The message format is also different.
Steps to Reproduce
Run pnpm test src/app/api/referrals/route.test.ts — the two affected tests will fail.
Expected Fix
Update the test expectations to match the actual implementation:
- Change
"1 invite(s) created and sent" → "1 invite(s) sent successfully"
- Update the email-failure test to expect
502 and check body.error contains "Failed to send" (reflecting the current emails-first, insert-on-success logic)
Tested
- Confirmed live:
POST /api/referrals with a valid email returns "1 invite(s) sent successfully" (status 200)
- Confirmed live: duplicate invite returns 400
"All these emails have already been invited"
Bug
Two test cases in
src/app/api/referrals/route.test.tshave expectations that don't match the current implementation insrc/app/api/referrals/route.ts.Bug 1 — Wrong success message expectation
Test (
should create referrals for valid emails):Actual code returns:
The string
"created and sent"never appears in the route's response.Bug 2 — Wrong status code when all emails fail to deliver
Test (
should keep created invites when email delivery fails):Actual code — when
successfulEmails.length === 0(all delivery failed):The route returns
502, not200. The message format is also different.Steps to Reproduce
Run
pnpm test src/app/api/referrals/route.test.ts— the two affected tests will fail.Expected Fix
Update the test expectations to match the actual implementation:
"1 invite(s) created and sent"→"1 invite(s) sent successfully"502and checkbody.errorcontains"Failed to send"(reflecting the current emails-first, insert-on-success logic)Tested
POST /api/referralswith a valid email returns"1 invite(s) sent successfully"(status 200)"All these emails have already been invited"