mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
fixing routes
This commit is contained in:
@ -1,47 +0,0 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
public function test_redirect_if_not_authenticated(): void
|
||||
{
|
||||
$response = $this->get('/servers');
|
||||
|
||||
$response->assertRedirect('/login');
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
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);
|
||||
}
|
||||
|
||||
public function test_password_can_be_confirmed(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$response = $this->post(route('password.confirm'), [
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
$response->assertSessionDoesntHaveErrors();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
<?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->assertSessionDoesntHaveErrors();
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
@ -5,7 +5,10 @@
|
||||
use App\Enums\UserRole;
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use App\Web\Pages\Settings\Users\Index;
|
||||
use App\Web\Pages\Settings\Users\Widgets\UsersList;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UserTest extends TestCase
|
||||
@ -16,12 +19,13 @@ public function test_create_user(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->post(route('settings.users.store'), [
|
||||
'name' => 'new user',
|
||||
'email' => 'newuser@example.com',
|
||||
'password' => 'password',
|
||||
'role' => UserRole::USER,
|
||||
])->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(Index::class)
|
||||
->callAction('create', [
|
||||
'name' => 'new user',
|
||||
'email' => 'newuser@example.com',
|
||||
'password' => 'password',
|
||||
'role' => UserRole::USER,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'name' => 'new user',
|
||||
@ -36,9 +40,11 @@ public function test_see_users_list(): void
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->get(route('settings.users.index'))
|
||||
->assertSuccessful()
|
||||
->assertSee($user->name);
|
||||
$this->get(Index::getUrl())
|
||||
->assertSuccessful();
|
||||
|
||||
Livewire::test(UsersList::class)
|
||||
->assertCanSeeTableRecords([$user]);
|
||||
}
|
||||
|
||||
public function test_must_be_admin_to_see_users_list(): void
|
||||
@ -48,9 +54,7 @@ public function test_must_be_admin_to_see_users_list(): void
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->get(route('settings.users.index'))
|
||||
$this->get(Index::getUrl())
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
@ -60,8 +64,8 @@ public function test_delete_user(): void
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->delete(route('settings.users.delete', $user))
|
||||
->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(UsersList::class)
|
||||
->callTableAction('delete', $user);
|
||||
|
||||
$this->assertDatabaseMissing('users', [
|
||||
'id' => $user->id,
|
||||
@ -72,24 +76,8 @@ public function test_cannot_delete_yourself(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$this->delete(route('settings.users.delete', $this->user))
|
||||
->assertSessionDoesntHaveErrors()
|
||||
->assertSessionHas('toast.type', 'error');
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $this->user->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_see_user(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->get(route('settings.users.show', $user))
|
||||
->assertSuccessful()
|
||||
->assertSee($user->name);
|
||||
Livewire::test(UsersList::class)
|
||||
->assertTableActionHidden('delete', $this->user);
|
||||
}
|
||||
|
||||
public function test_edit_user_info(): void
|
||||
@ -98,13 +86,14 @@ public function test_edit_user_info(): void
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->post(route('settings.users.update', $user), [
|
||||
'name' => 'new-name',
|
||||
'email' => 'newemail@example.com',
|
||||
'timezone' => 'Europe/London',
|
||||
'role' => UserRole::ADMIN,
|
||||
])
|
||||
->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(UsersList::class)
|
||||
->callTableAction('edit', $user, [
|
||||
'name' => 'new-name',
|
||||
'email' => 'newemail@example.com',
|
||||
'timezone' => 'Europe/London',
|
||||
'role' => UserRole::ADMIN,
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $user->id,
|
||||
@ -122,10 +111,11 @@ public function test_edit_user_projects(): void
|
||||
$user = User::factory()->create();
|
||||
$project = Project::factory()->create();
|
||||
|
||||
$this->post(route('settings.users.update-projects', $user), [
|
||||
'projects' => [$project->id],
|
||||
])
|
||||
->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(UsersList::class)
|
||||
->callTableAction('update-projects', $user, [
|
||||
'projects' => [$project->id],
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('user_project', [
|
||||
'user_id' => $user->id,
|
||||
@ -137,16 +127,19 @@ public function test_edit_user_projects_with_current_project(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
/** @var User $user */
|
||||
$user = User::factory()->create();
|
||||
$user->current_project_id = null;
|
||||
$user->save();
|
||||
|
||||
/** @var Project $project */
|
||||
$project = Project::factory()->create();
|
||||
|
||||
$this->post(route('settings.users.update-projects', $user), [
|
||||
'projects' => [$project->id],
|
||||
])
|
||||
->assertSessionDoesntHaveErrors();
|
||||
Livewire::test(UsersList::class)
|
||||
->callTableAction('update-projects', $user, [
|
||||
'projects' => [$project->id],
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('user_project', [
|
||||
'user_id' => $user->id,
|
||||
|
Reference in New Issue
Block a user