Skip to content

Commit 24480fc

Browse files
committed
update TurnstileTest
1 parent abe0740 commit 24480fc

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

tests/TurnstileTest.php

+30-7
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22

33
use Coderflex\FilamentTurnstile\Tests\Fixtures\ContactUs;
44
use Coderflex\FilamentTurnstile\Tests\Models\Contact;
5+
use Coderflex\LaravelTurnstile\Facades\LaravelTurnstile;
56
use Illuminate\Support\Facades\Config;
67

78
use function Pest\Livewire\livewire;
89

910
it('can render contact page', function () {
1011
livewire(ContactUs::class)
11-
->assertOk();
12+
->assertSuccessful();
1213
});
1314

1415
test('contact page has captcha field', function () {
1516
livewire(ContactUs::class)
1617
->assertFormFieldExists('cf-captcha', 'form');
1718
});
1819

19-
it('can send a message', function () {
20+
it('can return success response', function () {
2021
/**
2122
* Setting Turnstile keys to always pass the request
2223
*
@@ -27,13 +28,40 @@
2728
'turnstile_secret_key' => '1x0000000000000000000000000000000AA',
2829
]);
2930

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 () {
3053
/**
3154
* In this context, Alpine.js didn't function as expected due to the need to pass the `cf-captcha` field.
3255
* The value of the mentioned key is dynamically determined by the response from Cloudflare (CF) in the UI.
3356
* For more information, refer to the Cloudflare Turnstile documentation:
3457
*
3558
* @link https://developers.cloudflare.com/turnstile/
3659
*/
60+
Config::set('turnstile', [
61+
'turnstile_site_key' => '1x00000000000000000000AA',
62+
'turnstile_secret_key' => '1x0000000000000000000000000000000AA',
63+
]);
64+
3765
livewire(ContactUs::class)
3866
->fillForm([
3967
'name' => 'John Doe',
@@ -49,11 +77,6 @@
4977
});
5078

5179
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-
*/
5780
Config::set('turnstile', [
5881
'turnstile_site_key' => '2x00000000000000000000AB',
5982
'turnstile_secret_key' => '2x0000000000000000000000000000000AA',

0 commit comments

Comments
 (0)