<?php


namespace Tests\Services\CommodityService;


use App\Commodity;
use App\CommodityBarcode;
use App\OracleBasSKU;
use App\Owner;
use App\Services\CommodityService;
use Tests\TestCase;

class Get_HasOwnerIdsAndSkusTest extends TestCase
{
    /** @var CommodityService $service */
    private $service;
    private $data = [];
    public function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        cache()->flush();
        $this->service = app('CommodityService');
        $owner =  factory(Owner::class)->create();
        $commodity=factory(Commodity::class)->create(['owner_id'=>$owner->id]);
        $this->data['owner'] = $owner;
        $this->data['commodity'] = $commodity;
        $this->data['basSku']=OracleBasSKU::query()->orderByDesc('edittime')->first();
    }


    public function testGet_HasOwnerIdsAndSkus()
    {
        $commodities=$this->service->get_([$this->data['commodity']['owner_id']],[$this->data['commodity']['sku']]);
        $this->assertEquals(1,count($commodities));
    }
    public function tearDown(): void
    {
        $commodity_id=Commodity::query()->where('owner_id',$this->data['commodity']['owner_id'])->value('id');
        Commodity::query()->where('owner_id',$this->data['owner']['id'])->delete();
        CommodityBarcode::query()->where('commodity_id',$commodity_id)->delete();
        $this->data['owner']->delete();
        $this->data['commodity']->delete();
        cache()->flush();
        parent::tearDown(); // TODO: Change the autogenerated stub
    }
}
