<?php

namespace Tests\Feature\V3\AzmayeshSample;

use App\Models\Azmayesh;
use App\Models\AzmayeshSample;
use App\Models\Permission;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class DeleteTest extends TestCase
{
    use RefreshDatabase;
    /**
     * A basic feature test example.
     */
    public function test_user_should_have_azmayesh_management_permission(): void
    {
        $user = User::factory()->create();
        $azmayeshSample = AzmayeshSample::factory()->create();

        $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.delete', [$azmayeshSample->id]));

        $response->assertForbidden();
    }

    public function test_user_can_delete_azmayesh_sample(): void
    {
        $user = User::factory()
            ->has(Permission::factory([
                'name' => 'azmayesh-management'
            ]))
            ->create();
        $azmayeshSample = AzmayeshSample::factory()->create();

        $response = $this->actingAs($user)->postJson(route('v3.azmayesh_samples.delete', [$azmayeshSample->id]));

        $response->assertOk();

        $this->assertDatabaseMissing('azmayesh_samples', [
            'azmayesh_id' => $azmayeshSample->azmayesh_id,
            'data' => $azmayeshSample->data,
        ]);
    }
}
