<?php


namespace Tests\Inventory\Http\InventoryController;


use App\Authority;
use App\InventoryAccount;
use App\Owner;
use App\Role;
use App\User;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class InventoryControllerDeleteStockInventoryMissionTestMissionTest extends TestCase
{
    public $response=null;
    public $role;
    public $user;
    public $inventory;
    function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        if(!$this->user){
            $this->user = factory(User::class)->create();
            $this->role= Role::firstOrCreate([
                'name'=>'testRole',
            ]);
            $this->assertNotEmpty($this->role->id);
            $authority= Authority::where('name','库存管理-盘点')->first();
            DB::table('authority_role')->insert(['id_authority'=>$authority->id,'id_role'=>$this->role->id]);
            DB::table('user_role')->insert(['id_user'=>$this->user->id,'id_role'=>$this->role->id]);
            $this->inventory=factory(InventoryAccount::class)->create();
        }
        $this->response=$this->actingAs($this->user)->json('delete','http://bswas/inventory/deleteStockInventoryMission/'.$this->inventory['id']);
    }

    function testDeleteStockInventoryMissionNotHavingException(){
        $this->response->assertDontSee('Exception');
    }
    function testDeleteStockInventoryMissionHasSuccessJson(){
        $this->response->assertJson(['success'=>true,]);
    }
    function tearDown(): void
    {
        DB::table('user_role')->where('id_role',$this->role['id'])->delete();
        DB::table('authority_role')->where('id_role',$this->role['id'])->delete();
        User::where('id',$this->user['id'])->delete();
        Role::where('id',$this->role['id'])->delete();
        InventoryAccount::where('id',$this->inventory['id'])->forceDelete();
        parent::tearDown(); // TODO: Change the autogenerated stub
    }
}
