-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from CodeWithDennis/add-missing-tests
Add auth and profile test cases
- Loading branch information
Showing
4 changed files
with
164 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
use App\Filament\Pages\Auth\Login; | ||
use Filament\Facades\Filament; | ||
|
||
use function Pest\Livewire\livewire; | ||
|
||
test('an unauthenticated user can access the login page', function () { | ||
auth()->logout(); | ||
|
||
$this->get(Filament::getLoginUrl()) | ||
->assertOk(); | ||
}); | ||
|
||
test('an unauthenticated user can not access the admin panel', function () { | ||
auth()->logout(); | ||
|
||
$this->get('admin') | ||
->assertRedirect(Filament::getLoginUrl()); | ||
}); | ||
|
||
test('an unauthenticated user can login', function () { | ||
auth()->logout(); | ||
|
||
livewire(Login::class) | ||
->fillForm([ | ||
'email' => config('app.default_user.email'), | ||
'password' => config('app.default_user.password'), | ||
]) | ||
->assertActionExists('authenticate') | ||
->call('authenticate') | ||
->assertHasNoFormErrors(); | ||
}); | ||
|
||
test('an authenticated user can access the admin panel', function () { | ||
$this->get('admin') | ||
->assertOk(); | ||
}); | ||
|
||
test('an authenticated user can logout', function () { | ||
$this->get('admin') | ||
->assertOk(); | ||
|
||
$this->post('admin/logout') | ||
->assertRedirect(Filament::getLoginUrl()); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
use App\Filament\Pages\App\Profile; | ||
use App\Models\User; | ||
use Illuminate\Support\Str; | ||
|
||
use function Pest\Livewire\livewire; | ||
|
||
it('can render the profile page', function () { | ||
livewire(Profile::class) | ||
->assertSuccessful(); | ||
}); | ||
|
||
it('can update profile', function () { | ||
$updatedUser = User::factory()->make(); | ||
|
||
livewire(Profile::class) | ||
->fillForm([ | ||
'name' => $updatedUser->name, | ||
'email' => $updatedUser->email, | ||
]) | ||
->assertActionExists('save') | ||
->call('save') | ||
->assertHasNoFormErrors(); | ||
|
||
$this->assertDatabaseHas(User::class, [ | ||
'name' => $updatedUser->name, | ||
'email' => $updatedUser->email, | ||
]); | ||
}); | ||
|
||
it('can update password and authenticate', function () { | ||
$user = auth()->user(); | ||
|
||
livewire(Profile::class) | ||
->fillForm([ | ||
'password' => 'new-password', | ||
'passwordConfirmation' => 'new-password', | ||
]) | ||
->assertActionExists('save') | ||
->call('save') | ||
->assertHasNoFormErrors(); | ||
|
||
auth()->logout(); | ||
$this->assertGuest(); | ||
|
||
$this->assertTrue(auth()->attempt([ | ||
'email' => $user->email, | ||
'password' => 'new-password', | ||
])); | ||
}); | ||
|
||
it('can validate password confirmation', function () { | ||
livewire(Profile::class) | ||
->fillForm([ | ||
'password' => 'password', | ||
'passwordConfirmation' => 'different-password', | ||
]) | ||
->assertActionExists('save') | ||
->call('save') | ||
->assertHasFormErrors(['password' => ['same']]); | ||
}); | ||
|
||
it('can validate required', function ($column) { | ||
livewire(Profile::class) | ||
->fillForm([$column => null]) | ||
->assertActionExists('save') | ||
->call('save') | ||
->assertHasFormErrors([$column => ['required']]); | ||
})->with(['name', 'email']); | ||
|
||
it('can validate email', function () { | ||
livewire(Profile::class) | ||
->fillForm([ | ||
'email' => 'invalid-email-format', | ||
]) | ||
->assertActionExists('save') | ||
->call('save') | ||
->assertHasFormErrors(['email' => ['email']]); | ||
}); | ||
|
||
it('can validate unique email', function () { | ||
$user = User::factory()->create(); | ||
|
||
livewire(Profile::class) | ||
->fillForm([ | ||
'email' => $user->email, | ||
]) | ||
->assertActionExists('save') | ||
->call('save') | ||
->assertHasFormErrors(['email' => ['unique']]); | ||
}); | ||
|
||
it('can validate max length', function (string $column) { | ||
livewire(Profile::class) | ||
->fillForm([$column => Str::random(256)]) | ||
->assertActionExists('save') | ||
->call('save') | ||
->assertHasFormErrors([$column => ['max:255']]); | ||
})->with(['name', 'email']); |
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