Skip to content

Commit

Permalink
Creación primeros 2 tests de Usuarios
Browse files Browse the repository at this point in the history
  • Loading branch information
FazeElian committed Dec 18, 2023
1 parent aca0244 commit 869b3d0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 59 deletions.
40 changes: 0 additions & 40 deletions tests/Feature/CategoryTest.php

This file was deleted.

19 changes: 0 additions & 19 deletions tests/Feature/ExampleTest.php

This file was deleted.

54 changes: 54 additions & 0 deletions tests/Feature/UserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

// Importamos modelo de módulo -> 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);
}
}

0 comments on commit 869b3d0

Please sign in to comment.