<?php

namespace Tests\Services\CommodityService;

use App\Commodity;
use App\OracleBasSKU;
use App\Owner;
use App\Services\CommodityService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class GetParamsByBasSKUTest 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();
        $basSKU = factory(OracleBasSKU::class)->make(['customerid'=>$owner->code,'packid'=>'STANDARD']);
        $this->data['owner'] = $owner;
        $this->data['basSKU'] = $basSKU;
    }

    /**
     * @test
     */
    public function getParamsByBasSKU()
    {
        $created_param = $this->service->getParamsByBasSku($this->data['basSKU']);
        $this->assertNotNull($created_param['owner_id']);
        $this->assertEquals($created_param['owner_id'],$this->data['owner']['id']);
        $this->assertEquals($created_param['sku'],$this->data['basSKU']['sku']);
        $this->assertEquals($created_param['name'],$this->data['basSKU']['descr_c']);
        $this->assertEquals($created_param['length'],$this->data['basSKU']['skulength']);
        $this->assertEquals($created_param['width'],$this->data['basSKU']['skuwidth']);
        $this->assertEquals($created_param['height'],$this->data['basSKU']['skuhigh']);
        $this->assertEquals($created_param['volumn'],$this->data['basSKU']['cube']);
    }



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