-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e4b2b7
commit c63571e
Showing
2 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
<?php | ||
|
||
use App\Models\User; | ||
use App\Rules\ValidHCaptcha; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
it('can register', function () { | ||
|
||
Http::fake([ | ||
ValidHCaptcha::H_CAPTCHA_VERIFY_URL => Http::response(['success' => true]) | ||
]); | ||
|
||
$this->postJson('/register', [ | ||
'name' => 'Test User', | ||
'email' => '[email protected]', | ||
'hear_about_us' => 'google', | ||
'password' => 'secret', | ||
'password_confirmation' => 'secret', | ||
'agree_terms' => true, | ||
'h-captcha-response' => 'test-token', // Mock token for testing | ||
]) | ||
->assertSuccessful() | ||
->assertJsonStructure(['id', 'name', 'email']); | ||
$this->assertDatabaseHas('users', [ | ||
'name' => 'Test User', | ||
'email' => '[email protected]', | ||
]); | ||
|
||
$user = User::where('email', '[email protected]')->first(); | ||
expect($user)->not->toBeNull(); | ||
expect($user->meta)->toHaveKey('registration_ip'); | ||
expect($user->meta['registration_ip'])->toBe(request()->ip()); | ||
}); | ||
|
||
it('cannot register with existing email', function () { | ||
|
@@ -27,6 +36,7 @@ | |
'email' => '[email protected]', | ||
'password' => 'secret', | ||
'password_confirmation' => 'secret', | ||
'h-captcha-response' => 'test-token', | ||
]) | ||
->assertStatus(422) | ||
->assertJsonValidationErrors(['email']); | ||
|
@@ -48,15 +58,30 @@ | |
'password' => 'secret', | ||
'password_confirmation' => 'secret', | ||
'agree_terms' => true, | ||
'h-captcha-response' => 'test-token', | ||
]) | ||
->assertStatus(422) | ||
->assertJsonValidationErrors(['email']) | ||
->assertJson([ | ||
'message' => 'Disposable email addresses are not allowed.', | ||
'message' => 'Disposable email addresses are not allowed. (and 1 more error)', | ||
'errors' => [ | ||
'email' => [ | ||
'Disposable email addresses are not allowed.', | ||
], | ||
], | ||
]); | ||
}); | ||
|
||
it('requires hcaptcha token in production', function () { | ||
app()->detectEnvironment(fn() => 'production'); | ||
|
||
$this->postJson('/register', [ | ||
'name' => 'Test User', | ||
'email' => '[email protected]', | ||
'hear_about_us' => 'google', | ||
'password' => 'secret', | ||
'password_confirmation' => 'secret', | ||
]) | ||
->assertStatus(422) | ||
->assertJsonValidationErrors(['h-captcha-response']); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters