Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

1.6 KB
Raw Blame
<?php

use App\Models\Team;
use App\Models\TeamInvitation;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

test('team invitation normalizes email to lowercase', function () {
    // Create a team
    $team = Team::factory()->create();

    // Create invitation with mixed case email
    $invitation = TeamInvitation::create([
        'team_id' => $team->id,
        'uuid' => 'test-uuid-123',
        'email' => '[email protected]', // Mixed case
        'role' => 'member',
        'link' => 'https://example.com/invite/test-uuid-123',
        'via' => 'link',
    ]);

    // Verify email was normalized to lowercase
    expect($invitation->email)->toBe('[email protected]');
});

test('team invitation works with existing user email', function () {
    // Create a team
    $team = Team::factory()->create();

    // Create a user with lowercase email
    $user = User::factory()->create([
        'email' => '[email protected]',
        'name' => 'Test User',
    ]);

    // Create invitation with mixed case email
    $invitation = TeamInvitation::create([
        'team_id' => $team->id,
        'uuid' => 'test-uuid-123',
        'email' => '[email protected]', // Mixed case
        'role' => 'member',
        'link' => 'https://example.com/invite/test-uuid-123',
        'via' => 'link',
    ]);

    // Verify the invitation email matches the user email (both normalized)
    expect($invitation->email)->toBe($user->email);

    // Verify user lookup works
    $foundUser = User::whereEmail($invitation->email)->first();
    expect($foundUser)->not->toBeNull();
    expect($foundUser->id)->toBe($user->id);
});