mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-16 16:37:47 +00:00
refactor: rebase on Livewire 4 starter kit
This commit is contained in:
parent
b097b0a7d7
commit
e660da46fb
69 changed files with 1967 additions and 942 deletions
|
|
@ -13,13 +13,13 @@ test('login screen can be rendered', function (): void {
|
|||
test('users can authenticate using the login screen', function (): void {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = Livewire::test('auth.login')
|
||||
->set('email', $user->email)
|
||||
->set('password', 'password')
|
||||
->call('login');
|
||||
$response = $this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertHasNoErrors()
|
||||
->assertSessionHasNoErrors()
|
||||
->assertRedirect(route('dashboard', absolute: false));
|
||||
|
||||
$this->assertAuthenticated();
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
|||
test('email verification screen can be rendered', function (): void {
|
||||
$user = User::factory()->unverified()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get('/verify-email');
|
||||
$response = $this->actingAs($user)->get(route('verification.notice'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('email can be verified', function (): void {
|
||||
|
|
|
|||
|
|
@ -7,33 +7,7 @@ uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
|||
test('confirm password screen can be rendered', function (): void {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get('/confirm-password');
|
||||
$response = $this->actingAs($user)->get(route('password.confirm'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
||||
|
||||
test('password can be confirmed', function (): void {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('auth.confirm-password')
|
||||
->set('password', 'password')
|
||||
->call('confirmPassword');
|
||||
|
||||
$response
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('dashboard', absolute: false));
|
||||
});
|
||||
|
||||
test('password is not confirmed with invalid password', function (): void {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('auth.confirm-password')
|
||||
->set('password', 'wrong-password')
|
||||
->call('confirmPassword');
|
||||
|
||||
$response->assertHasErrors(['password']);
|
||||
$response->assertOk();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,9 +17,7 @@ test('reset password link can be requested', function (): void {
|
|||
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::test('auth.forgot-password')
|
||||
->set('email', $user->email)
|
||||
->call('sendPasswordResetLink');
|
||||
$this->post(route('password.request'), ['email' => $user->email]);
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class);
|
||||
});
|
||||
|
|
@ -29,14 +27,12 @@ test('reset password screen can be rendered', function (): void {
|
|||
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::test('auth.forgot-password')
|
||||
->set('email', $user->email)
|
||||
->call('sendPasswordResetLink');
|
||||
$this->post(route('password.request'), ['email' => $user->email]);
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class, function ($notification): true {
|
||||
$response = $this->get('/reset-password/'.$notification->token);
|
||||
$response = $this->get(route('password.reset', $notification->token));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertOk();
|
||||
|
||||
return true;
|
||||
});
|
||||
|
|
@ -47,19 +43,18 @@ test('password can be reset with valid token', function (): void {
|
|||
|
||||
$user = User::factory()->create();
|
||||
|
||||
Livewire::test('auth.forgot-password')
|
||||
->set('email', $user->email)
|
||||
->call('sendPasswordResetLink');
|
||||
$this->post(route('password.request'), ['email' => $user->email]);
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user): true {
|
||||
$response = Livewire::test('auth.reset-password', ['token' => $notification->token])
|
||||
->set('email', $user->email)
|
||||
->set('password', 'password')
|
||||
->set('password_confirmation', 'password')
|
||||
->call('resetPassword');
|
||||
$response = $this->post(route('password.update'), [
|
||||
'token' => $notification->token,
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertHasNoErrors()
|
||||
->assertSessionHasNoErrors()
|
||||
->assertRedirect(route('login', absolute: false));
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -3,21 +3,20 @@
|
|||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('registration screen can be rendered', function (): void {
|
||||
$response = $this->get('/register');
|
||||
$response = $this->get(route('register'));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('new users can register', function (): void {
|
||||
$response = Livewire::test('auth.register')
|
||||
->set('name', 'Test User')
|
||||
->set('email', 'test@example.com')
|
||||
->set('password', 'password')
|
||||
->set('password_confirmation', 'password')
|
||||
->call('register');
|
||||
$response = $this->post(route('register.store'), [
|
||||
'name' => 'John Doe',
|
||||
'email' => 'test@example.com',
|
||||
'password' => 'password',
|
||||
'password_confirmation' => 'password',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertHasNoErrors()
|
||||
$response->assertSessionHasNoErrors()
|
||||
->assertRedirect(route('dashboard', absolute: false));
|
||||
|
||||
$this->assertAuthenticated();
|
||||
|
|
|
|||
34
tests/Feature/Auth/TwoFactorChallengeTest.php
Normal file
34
tests/Feature/Auth/TwoFactorChallengeTest.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Fortify\Features;
|
||||
|
||||
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
|
||||
|
||||
test('two_factor_challenge_redirects_to_login_when_not_authenticated', function (): void {
|
||||
if (! Features::canManageTwoFactorAuthentication()) {
|
||||
$this->markTestSkipped('Two-factor authentication is not enabled.');
|
||||
}
|
||||
|
||||
$response = $this->get(route('two-factor.login'));
|
||||
|
||||
$response->assertRedirect(route('login'));
|
||||
});
|
||||
|
||||
test('two_factor_challenge_can_be_rendered', function (): void {
|
||||
if (! Features::canManageTwoFactorAuthentication()) {
|
||||
$this->markTestSkipped('Two-factor authentication is not enabled.');
|
||||
}
|
||||
|
||||
Features::twoFactorAuthentication([
|
||||
'confirm' => true,
|
||||
'confirmPassword' => true,
|
||||
]);
|
||||
|
||||
$user = User::factory()->withTwoFactor()->create();
|
||||
|
||||
$this->post(route('login.store'), [
|
||||
'email' => $user->email,
|
||||
'password' => 'password',
|
||||
])->assertRedirect(route('two-factor.login'));
|
||||
});
|
||||
|
|
@ -12,7 +12,7 @@ test('password can be updated', function (): void {
|
|||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('settings.password')
|
||||
$response = Livewire::test('pages::settings.password')
|
||||
->set('current_password', 'password')
|
||||
->set('password', 'new-password')
|
||||
->set('password_confirmation', 'new-password')
|
||||
|
|
@ -20,7 +20,7 @@ test('password can be updated', function (): void {
|
|||
|
||||
$response->assertHasNoErrors();
|
||||
|
||||
expect(Hash::check('new-password', $user->refresh()->password))->toBeTrue();
|
||||
$this->assertTrue(Hash::check('new-password', $user->refresh()->password));
|
||||
});
|
||||
|
||||
test('correct password must be provided to update password', function (): void {
|
||||
|
|
@ -30,7 +30,7 @@ test('correct password must be provided to update password', function (): void {
|
|||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('settings.password')
|
||||
$response = Livewire::test('pages::settings.password')
|
||||
->set('current_password', 'wrong-password')
|
||||
->set('password', 'new-password')
|
||||
->set('password_confirmation', 'new-password')
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ test('profile information can be updated', function (): void {
|
|||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('settings.profile')
|
||||
$response = Livewire::test('pages::settings.profile')
|
||||
->set('name', 'Test User')
|
||||
->set('email', 'test@example.com')
|
||||
->call('updateProfileInformation');
|
||||
|
|
@ -34,7 +34,7 @@ test('email verification status is unchanged when email address is unchanged', f
|
|||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('settings.profile')
|
||||
$response = Livewire::test('pages::settings.profile')
|
||||
->set('name', 'Test User')
|
||||
->set('email', $user->email)
|
||||
->call('updateProfileInformation');
|
||||
|
|
@ -49,7 +49,7 @@ test('user can delete their account', function (): void {
|
|||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('settings.delete-user-form')
|
||||
$response = Livewire::test('pages::settings.delete-user-form')
|
||||
->set('password', 'password')
|
||||
->call('deleteUser');
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ test('correct password must be provided to delete account', function (): void {
|
|||
|
||||
$this->actingAs($user);
|
||||
|
||||
$response = Livewire::test('settings.delete-user-form')
|
||||
$response = Livewire::test('pages::settings.delete-user-form')
|
||||
->set('password', 'wrong-password')
|
||||
->call('deleteUser');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue