|
2 | 2 |
|
3 | 3 | use Coderflex\FilamentTurnstile\Tests\Fixtures\ContactUs;
|
4 | 4 | use Coderflex\FilamentTurnstile\Tests\Models\Contact;
|
| 5 | +use Coderflex\LaravelTurnstile\Facades\LaravelTurnstile; |
5 | 6 | use Illuminate\Support\Facades\Config;
|
6 | 7 |
|
7 | 8 | use function Pest\Livewire\livewire;
|
8 | 9 |
|
9 | 10 | it('can render contact page', function () {
|
10 | 11 | livewire(ContactUs::class)
|
11 |
| - ->assertOk(); |
| 12 | + ->assertSuccessful(); |
12 | 13 | });
|
13 | 14 |
|
14 | 15 | test('contact page has captcha field', function () {
|
15 | 16 | livewire(ContactUs::class)
|
16 | 17 | ->assertFormFieldExists('cf-captcha', 'form');
|
17 | 18 | });
|
18 | 19 |
|
19 |
| -it('can send a message', function () { |
| 20 | +it('can return success response', function () { |
20 | 21 | /**
|
21 | 22 | * Setting Turnstile keys to always pass the request
|
22 | 23 | *
|
|
27 | 28 | 'turnstile_secret_key' => '1x0000000000000000000000000000000AA',
|
28 | 29 | ]);
|
29 | 30 |
|
| 31 | + $response = LaravelTurnstile::validate('XXXX.DUMMY.TOKEN.XXXX'); |
| 32 | + |
| 33 | + expect($response['success'])->toBeTrue(); |
| 34 | +}); |
| 35 | + |
| 36 | +it('can does not return success response', function () { |
| 37 | + /** |
| 38 | + * Setting Turnstile keys to always block the request |
| 39 | + * |
| 40 | + * @link https://developers.cloudflare.com/turnstile/reference/testing/#dummy-sitekeys-and-secret-keys |
| 41 | + */ |
| 42 | + Config::set('turnstile', [ |
| 43 | + 'turnstile_site_key' => '2x00000000000000000000AB', |
| 44 | + 'turnstile_secret_key' => '2x0000000000000000000000000000000AA', |
| 45 | + ]); |
| 46 | + |
| 47 | + $response = LaravelTurnstile::validate('XXXX.DUMMY.TOKEN.XXXX'); |
| 48 | + |
| 49 | + expect($response['success'])->toBeFalse(); |
| 50 | +}); |
| 51 | + |
| 52 | +it('can send a message', function () { |
30 | 53 | /**
|
31 | 54 | * In this context, Alpine.js didn't function as expected due to the need to pass the `cf-captcha` field.
|
32 | 55 | * The value of the mentioned key is dynamically determined by the response from Cloudflare (CF) in the UI.
|
33 | 56 | * For more information, refer to the Cloudflare Turnstile documentation:
|
34 | 57 | *
|
35 | 58 | * @link https://developers.cloudflare.com/turnstile/
|
36 | 59 | */
|
| 60 | + Config::set('turnstile', [ |
| 61 | + 'turnstile_site_key' => '1x00000000000000000000AA', |
| 62 | + 'turnstile_secret_key' => '1x0000000000000000000000000000000AA', |
| 63 | + ]); |
| 64 | + |
37 | 65 | livewire(ContactUs::class)
|
38 | 66 | ->fillForm([
|
39 | 67 | 'name' => 'John Doe',
|
|
49 | 77 | });
|
50 | 78 |
|
51 | 79 | it('cannot send a message', function () {
|
52 |
| - /** |
53 |
| - * Setting Turnstile keys to always block the request |
54 |
| - * |
55 |
| - * @link https://developers.cloudflare.com/turnstile/reference/testing/#dummy-sitekeys-and-secret-keys |
56 |
| - */ |
57 | 80 | Config::set('turnstile', [
|
58 | 81 | 'turnstile_site_key' => '2x00000000000000000000AB',
|
59 | 82 | 'turnstile_secret_key' => '2x0000000000000000000000000000000AA',
|
|
0 commit comments