Skip to content

fix(referrals): test expectations don't match route implementation #348

@forgou37

Description

@forgou37

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:

  1. Change "1 invite(s) created and sent""1 invite(s) sent successfully"
  2. 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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions