<?php

namespace Tests\Feature\V3\RoadItemsProject;

use App\Models\LogList;
use App\Models\Permission;
use App\Models\RoadItemsProject;
use App\Models\User;
use App\Models\UserActivityLog;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class DeleteTest extends TestCase
{
    use RefreshDatabase, WithFaker;

    public function test_user_should_have_show_road_item_supervise_delete_permission(): void
    {
        $user = User::factory()->create();
        $roadItem = RoadItemsProject::factory()->create();
        $response = $this->actingAs($user)->postJson(route('v3.road_items.delete', [$roadItem->id]));
        $response->assertForbidden();
    }

    public function test_user_cannot_access_authentication_delete(): void
    {
        $roadItem = RoadItemsProject::factory()->create();
        $response =$this->postJson(route('v3.road_items.delete', [$roadItem->id]));
        $response->assertStatus(401);

    }

    public function test_user_can_delete_road_item(): void
    {
        $user = User::factory()
            ->has(Permission::factory([
                'name' => 'delete-road-item'
            ]))
            ->create();

        $logList = LogList::factory()->create([
            'log_unique_code' => 1151,
        ]);
        UserActivityLog::factory()->create();
        $roadItem = RoadItemsProject::factory()->create();
        $response = $this->actingAs($user)->postJson(route('v3.road_items.delete', [$roadItem->id]));

        $response->assertOk()
            ->assertJson([
                'message' => __('messages.successful'),
            ]);
        $this->assertDatabaseMissing('road_items_projects', [
            'id' => $roadItem->id,
        ]);
    }
}
