Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creación primeros 2 tests de Usuarios #92

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading