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

feat(testing): implement a basic testing #222

Closed
wants to merge 3 commits into from
Closed
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
137 changes: 137 additions & 0 deletions tests/Unit/AdminTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php

namespace Tests\Unit;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
use App\Models\User;
use App\Models\ResourceType;
use App\Models\ElementType;
use App\Models\TaskType;

class AdminTest extends TestCase
{
use RefreshDatabase;

protected $user;

protected function setUp(): void
{
parent::setUp();
$this->user = User::factory()->create([
'name' => 'Gemma Palanca',
'surname' => 'UserSurname'
]);
}

public function test_user_can_access_application()
{
$response = $this->actingAs($this->user)->get('/home');
$response->assertStatus(200);
}

public function test_user_can_create_resource_type()
{
$this->actingAs($this->user);

$resourceType = ResourceType::create([
'name' => 'ResourceType1',
'description' => null,
]);

$this->assertDatabaseHas('resource_types', [
'id' => $resourceType->id,
'name' => 'ResourceType1',
'description' => null,
]);
}

public function test_user_can_create_element_type()
{
$this->actingAs($this->user);

$elementType = ElementType::create([
'name' => 'ElementType1',
'description' => null,
]);

$this->assertDatabaseHas('element_types', [
'id' => $elementType->id,
'name' => 'ElementType1',
'description' => null,
]);
}

public function test_user_can_delete_element_type()
{
$this->actingAs($this->user);

$elementType = ElementType::create([
'name' => 'ElementTypeToDelete',
'description' => null,
]);

$elementType->delete();

$this->assertDatabaseMissing('element_types', [
'id' => $elementType->id,
]);
}



public function test_user_can_create_task_type()
{
$this->actingAs($this->user);

$taskType = TaskType::create([
'name' => 'TaskType1',
'description' => null,
]);

$this->assertDatabaseHas('task_types', [
'id' => $taskType->id,
'name' => 'TaskType1',
'description' => null,
]);
}

public function test_user_can_edit_existing_user()
{
$this->actingAs($this->user);

$existingUser = User::factory()->create([
'name' => 'Old Name',
'surname' => 'Old Surname'
]);

$existingUser->update([
'name' => 'New Name',
'surname' => 'New Surname'
]);

$this->assertDatabaseHas('users', [
'id' => $existingUser->id,
'name' => 'New Name',
'surname' => 'New Surname'
]);
}

public function test_user_can_delete_existing_user()
{
$this->actingAs($this->user);

$existingUser = User::factory()->create([
'name' => 'User To Delete',
'surname' => 'Surname To Delete'
]);

$existingUser->delete();

$this->assertDatabaseMissing('users', [
'id' => $existingUser->id
]);
}


}