<?php


namespace Tests\Inventory\Http\InventoryController;


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

class InventoryController_SearchStockInventoryRecordTest extends TestCase
{
    public $response=null;
    public $role;
    public $user;
    public $inventory;
    public $inventoryMissions;
    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->inventoryMissions=InventoryAccountMission::create([
                'inventory_account_id'=>$this->inventory['id'],
                'location'=>'A12-10-01',
                'commodity_id'=>256226,
                'produced_at'=>null,
                'valid_at'=>null,
                'stored_at'=>null,
                'batch_number'=>'',
                'erp_type_position'=>'',
                'quality'=>'',
                'stored_amount'=>50,
                'valid_amount'=>'',
                'verified_amount'=>'',
                're_checked_amount'=>'',
                'difference_amount'=>'',
                'occupied_amount'=>'',
                'checked'=>'否',
                'returned'=>'无',
            ]);
        }
        $this->response=$this->actingAs($this->user)->json('post','http://bswas/inventory/searchStockInventoryRecord',
            [   'location'=>'A12-10-01',
                'barcode'=>'9787511715364',
                'inventoryId'=>$this->inventory['id'],
                ]);
    }
    function testSearchStockInventoryRecordNotHavingException(){
        $this->response->assertDontSee('Exception');
    }
    function testSearchStockInventoryRecordSuccessJson(){
        $this->response->assertJson([
            'success'=>true,
            'data'=>$this->response->json()['data'],
        ]);
    }

    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();
        InventoryAccountMission::where('inventory_account_id',$this->inventory['id'])->delete();
        InventoryAccount::where('id',$this->inventory['id'])->forceDelete();
        parent::tearDown(); // TODO: Change the autogenerated stub
    }
}
