test email signup flow
This commit is contained in:
parent
a95903ed05
commit
9945163a2f
12 changed files with 631 additions and 0 deletions
50
backend/tests/Feature/Auth/SignupEndpointTest.php
Normal file
50
backend/tests/Feature/Auth/SignupEndpointTest.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue