fix notification chanels and more tests (#108)

* fix notification chanels and more tests

* fix code style
This commit is contained in:
Saeed Vaziry
2024-02-16 21:10:17 +01:00
committed by GitHub
parent b75df8e1c5
commit f70963d6bb
103 changed files with 484 additions and 112 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace Tests\Feature\Auth;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AuthenticationTest extends TestCase
{
use RefreshDatabase;
public function test_login_screen_can_be_rendered(): void
{
$response = $this->get('/login');
$response->assertStatus(200);
}
public function test_users_can_authenticate_using_the_login_screen(): void
{
$response = $this->post('/login', [
'email' => $this->user->email,
'password' => 'password',
]);
$this->assertAuthenticated();
$response->assertRedirect(RouteServiceProvider::HOME);
}
public function test_users_can_not_authenticate_with_invalid_password(): void
{
$this->post('/login', [
'email' => $this->user->email,
'password' => 'wrong-password',
]);
$this->assertGuest();
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace Tests\Feature\Auth;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class LogoutTest extends TestCase
{
use RefreshDatabase;
public function test_logout(): void
{
$this->actingAs($this->user);
$this->post(route('logout'))->assertRedirect('/');
$this->assertFalse(auth()->check());
}
public function test_user_still_logged_in(): void
{
$this->actingAs($this->user);
$this->get(route('login'))->assertRedirect(route('servers'));
$this->assertTrue(auth()->check());
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace Tests\Feature\Auth;
use Illuminate\Foundation\Testing\RefreshDatabase;
use JsonException;
use Tests\TestCase;
class PasswordConfirmationTest extends TestCase
{
use RefreshDatabase;
public function test_confirm_password_screen_can_be_rendered(): void
{
$this->actingAs($this->user);
$response = $this->get(route('password.confirm'));
$response->assertStatus(200);
}
/**
* @throws JsonException
*/
public function test_password_can_be_confirmed(): void
{
$this->actingAs($this->user);
$response = $this->post(route('password.confirm'), [
'password' => 'password',
]);
$response->assertRedirect();
$response->assertSessionHasNoErrors();
}
public function test_password_is_not_confirmed_with_invalid_password(): void
{
$this->actingAs($this->user);
$response = $this->post(route('password.confirm'), [
'password' => 'wrong-password',
]);
$response->assertSessionHasErrors();
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace Tests\Feature\Auth;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
class PasswordResetTest extends TestCase
{
use RefreshDatabase;
public function test_reset_password_link_screen_can_be_rendered(): void
{
$response = $this->get('/forgot-password');
$response->assertStatus(200);
}
public function test_reset_password_link_can_be_requested(): void
{
Notification::fake();
$this->post('/forgot-password', ['email' => $this->user->email]);
Notification::assertSentTo($this->user, ResetPassword::class);
}
public function test_reset_password_screen_can_be_rendered(): void
{
Notification::fake();
$this->post('/forgot-password', ['email' => $this->user->email]);
Notification::assertSentTo($this->user, ResetPassword::class, function ($notification) {
$response = $this->get('/reset-password/'.$notification->token);
$response->assertStatus(200);
return true;
});
}
public function test_password_can_be_reset_with_valid_token(): void
{
Notification::fake();
$this->post('/forgot-password', ['email' => $this->user->email]);
Notification::assertSentTo($this->user, ResetPassword::class, function ($notification) {
$response = $this->post('/reset-password', [
'token' => $notification->token,
'email' => $this->user->email,
'password' => 'password',
'password_confirmation' => 'password',
]);
$response->assertSessionHasNoErrors();
return true;
});
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Tests\Feature\Auth;
use App\Http\Livewire\Profile\UpdatePassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Livewire\Livewire;
use Tests\TestCase;
class PasswordUpdateTest extends TestCase
{
use RefreshDatabase;
public function test_password_can_be_updated(): void
{
$this->actingAs($this->user);
Livewire::test(UpdatePassword::class)
->set('current_password', 'password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('update')
->assertSuccessful();
$this->assertTrue(Hash::check('new-password', $this->user->refresh()->password));
}
public function test_correct_password_must_be_provided_to_update_password(): void
{
$this->actingAs($this->user);
Livewire::test(UpdatePassword::class)
->set('current_password', 'wrong-password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('update')
->assertHasErrors();
}
}