diff --git a/tests/Feature/CategoryTest.php b/tests/Feature/CategoryTest.php deleted file mode 100644 index d61c048..0000000 --- a/tests/Feature/CategoryTest.php +++ /dev/null @@ -1,40 +0,0 @@ - "Categoría ejemplo 1", - // "description" => "Descripción Categoria ejemplo 1" - // ]; - - // $response = $this->post("products/categories", $category); - - // $response->assertStatus(302); - // $response->assertRedirect(route("categories.index")); - - // $this->assertDatabaseCount("categories", 3); - - // $lastCategoryCreated = Category::query()->latest()->first(); - - // $this->assertDatabaseHas("categories", [ - // "name" => $lastCategoryCreated->name, - // "description" => $lastCategoryCreated->description, - // ]); - - // $this->assertDatabaseHas("categories", $category); - - // $this->assertEquals($category["name"], $lastCategoryCreated->name); - // $this->assertEquals($category["description"], $lastCategoryCreated->description); - // } -} diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index 8364a84..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,19 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -} diff --git a/tests/Feature/UserTest.php b/tests/Feature/UserTest.php new file mode 100644 index 0000000..2b09c50 --- /dev/null +++ b/tests/Feature/UserTest.php @@ -0,0 +1,54 @@ + Usuario +use App\Models\User; + +class UserTest extends TestCase +{ + /** + * A basic feature test example. + */ + // public function test_example(): void + // { + // $response = $this->get('/'); + + // $response->assertStatus(200); + // } + + // Test: Un usuario puede acceder a la vista de Inicio de Sesión + public function test_a_user_can_view_a_login_form() { + $response = $this->get('/login'); + + $response->assertSuccessful(); + $response->assertViewIs('auth.login'); + } + + // Test: Un usuario puede Iniciar Sesión + public function test_a_user_can_login() { + // Crear un usuario de prueba + $user = User::factory()->create([ + 'name' => "name example", + 'email' => 'test@example.com', + 'password' => bcrypt('password'), // Cifrar contraseña + ]); + + // Visitar la página de inicio de sesión + $response = $this->post('/login', [ + 'name' => "name example", + 'email' => 'test@example.com', + 'password' => 'password', + ]); + + // Verificar que el usuario esté redirigido después de iniciar sesión + $response->assertRedirect('/home'); // Redirección a la página principal de Administrador + + // Verificar que el usuario esté autenticado + $this->assertAuthenticatedAs($user); + } +}