50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Auth;
|
|
|
|
use App\Email\EmailConfirmationToken\EmailConfirmationTokenRepository;
|
|
use App\Shared\ValueObject\EmailAddress;
|
|
use App\User\CreateUserDto;
|
|
use App\User\UserRepository;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class SignupEndpointTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_signup_creates_a_pending_user_and_confirmation_token(): void
|
|
{
|
|
$response = $this->postJson('/api/signup', [
|
|
'email' => 'Founder@EXAMPLE.COM',
|
|
]);
|
|
|
|
$response->assertCreated();
|
|
$user = app(UserRepository::class)->findByEmail(
|
|
new EmailAddress('Founder@example.com'),
|
|
);
|
|
$this->assertNotNull($user);
|
|
$this->assertNull($user->getPasswordHash());
|
|
$this->assertNotNull(
|
|
app(EmailConfirmationTokenRepository::class)
|
|
->findByUser($user),
|
|
);
|
|
}
|
|
|
|
public function test_signup_rejects_an_existing_confirmed_account(): void
|
|
{
|
|
app(UserRepository::class)->create(new CreateUserDto(
|
|
email: new EmailAddress('user@example.com'),
|
|
passwordHash: 'hashed-password',
|
|
));
|
|
|
|
$response = $this->postJson('/api/signup', [
|
|
'email' => 'user@example.com',
|
|
]);
|
|
|
|
$response->assertConflict();
|
|
$response->assertJson([
|
|
'error' => 'user@example.com already has an account',
|
|
]);
|
|
}
|
|
}
|