<?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_OnlyOwnerIdsTest extends TestCase
{
    /** @var CommodityService $service */
    private $service;
    private $data = [];
    public function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        $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;
    }

    public function testGet_OnlyOwnerIds()
    {
        $commodities=$this->service->get_([$this->data['commodity']['owner_id']]);
        $this->assertNotNull($commodities);
        $this->assertEquals($this->data['commodity']['sku'],$commodities->first()['sku']);
    }
    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
    }
}
