<?php


namespace Tests\Services\CommodityService;


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

class GetParamsByBasSkusTest extends TestCase
{
    /** @var CommodityService $service */
    public $service;
    public $bas_skus;
    private $data = [];
    public function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        cache()->flush();
        $this->service=app(CommodityService::class);
        $owner =  factory(Owner::class)->create();
        $basSKU = factory(OracleBasSKU::class)->make(['customerid'=>$owner->code,'packid'=>'STANDARD']);
        $this->data['owner'] = $owner;
        $this->data['basSKU'] = $basSKU;
        $this->bas_skus=collect();
        $this->bas_skus->add($basSKU);

    }
    public function testGetParamsByBasSkus(){

            $insert_params=$this->service->getParamsByBasSkus($this->bas_skus);
            if ($insert_params){
                $this->assertNotNull($insert_params);
                $key=$this->data['basSKU']['sku'].$this->data['owner']['id'];
                $this->assertEquals($insert_params[$key]['owner_id'],$this->data['owner']['id']);
                $this->assertEquals($insert_params[$key]['sku'],$this->data['basSKU']['sku']);
                $this->assertEquals($insert_params[$key]['name'],$this->data['basSKU']['descr_c']);
            }else{
                $this->assertNull($insert_params);
            }

    }

    public function tearDown(): void
    {
        $this->data['owner']->delete();
        parent::tearDown(); // TODO: Change the autogenerated stub
    }
}
