-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
5 changed files
with
77 additions
and
31 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
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
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
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
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,6 +1,8 @@ | ||
<?php | ||
|
||
use Coderflex\FilamentTurnstile\Tests\Fixtures\ContactUs; | ||
use Coderflex\FilamentTurnstile\Tests\Models\Contact; | ||
use Illuminate\Support\Facades\Config; | ||
|
||
use function Pest\Livewire\livewire; | ||
|
||
|
@@ -13,3 +15,51 @@ | |
livewire(ContactUs::class) | ||
->assertFormFieldExists('cf-captcha', 'form'); | ||
}); | ||
|
||
it('can send a message', function () { | ||
/** | ||
* Setting Turnstile keys to always pass the request | ||
* | ||
* @see https://developers.cloudflare.com/turnstile/reference/testing/#dummy-sitekeys-and-secret-keys | ||
*/ | ||
Config::set('turnstile', [ | ||
'turnstile_site_key' => '1x00000000000000000000AA', | ||
'turnstile_secret_key' => '1x0000000000000000000000000000000AA', | ||
]); | ||
|
||
livewire(ContactUs::class) | ||
->fillForm([ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
'content' => 'This is a simple message', | ||
]) | ||
->call('send') | ||
->assertHasNoFormErrors(); | ||
|
||
expect(Contact::get()) | ||
->toHaveCount(1); | ||
}); | ||
|
||
it('cannot send a message', function () { | ||
/** | ||
* Setting Turnstile keys to always block the request | ||
* | ||
* @see https://developers.cloudflare.com/turnstile/reference/testing/#dummy-sitekeys-and-secret-keys | ||
*/ | ||
Config::set('turnstile', [ | ||
'turnstile_site_key' => '2x00000000000000000000AB', | ||
'turnstile_secret_key' => '2x0000000000000000000000000000000AA', | ||
]); | ||
|
||
livewire(ContactUs::class) | ||
->fillForm([ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
'content' => 'This is a simple message', | ||
]) | ||
->call('send') | ||
->assertHasFormErrors(['cf-captcha']); | ||
|
||
expect(Contact::get()) | ||
->toHaveCount(0); | ||
}); |