byos_laravel/tests/Feature/Settings/ProfileUpdateTest.php
Benjamin Nussbaum b4b6286172
Some checks are pending
tests / ci (push) Waiting to run
refactor: apply rector
2025-09-24 20:35:48 +02:00

77 lines
2 KiB
PHP

<?php
use App\Models\User;
use Livewire\Volt\Volt;
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
test('profile page is displayed', function (): void {
$this->actingAs($user = User::factory()->create());
$this->get('/settings/profile')->assertOk();
});
test('profile information can be updated', function (): void {
$user = User::factory()->create();
$this->actingAs($user);
$response = Volt::test('settings.profile')
->set('name', 'Test User')
->set('email', 'test@example.com')
->call('updateProfileInformation');
$response->assertHasNoErrors();
$user->refresh();
expect($user->name)->toEqual('Test User');
expect($user->email)->toEqual('test@example.com');
expect($user->email_verified_at)->toBeNull();
});
test('email verification status is unchanged when email address is unchanged', function (): void {
$user = User::factory()->create();
$this->actingAs($user);
$response = Volt::test('settings.profile')
->set('name', 'Test User')
->set('email', $user->email)
->call('updateProfileInformation');
$response->assertHasNoErrors();
expect($user->refresh()->email_verified_at)->not->toBeNull();
});
test('user can delete their account', function (): void {
$user = User::factory()->create();
$this->actingAs($user);
$response = Volt::test('settings.delete-user-form')
->set('password', 'password')
->call('deleteUser');
$response
->assertHasNoErrors()
->assertRedirect('/');
expect($user->fresh())->toBeNull();
expect(auth()->check())->toBeFalse();
});
test('correct password must be provided to delete account', function (): void {
$user = User::factory()->create();
$this->actingAs($user);
$response = Volt::test('settings.delete-user-form')
->set('password', 'wrong-password')
->call('deleteUser');
$response->assertHasErrors(['password']);
expect($user->fresh())->not->toBeNull();
});