<?php


namespace Tests\Services\CommodityBarcodeService;


use App\OracleBasSKU;
use App\Services\CommodityBarcodeService;
use App\ValueStore;
use Tests\TestCase;

class GetByWmsTest extends TestCase
{

    /**
     * @var CommodityBarcodeService $service
     */
    public $service;
    public $bas_skus;
    public $created_at;
    public function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub
        $this->created_at = config('sync.commodity_sync.created_at');
        $last_time = ValueStore::query()->where('name',$this->created_at)->value('value');
        $startDate = \Illuminate\Support\Carbon::now()->subSeconds(65);
        $this->service = app(CommodityBarcodeService::class);
        $this->bas_skus = OracleBasSKU::query()
            ->select('customerid', 'sku', 'descr_c', 'alternate_sku1', 'alternate_sku2', 'alternate_sku3', 'skulength', 'skuwidth', 'skuhigh', 'cube', 'packid', 'addtime', 'edittime')
            ->where('addTime', '>=', $last_time??$startDate)
            ->orderByDesc('addtime')
            ->get();
    }


    public function testGetByWms()
    {
        if ($this->bas_skus->isEmpty()) {
            $this->assertEmpty($this->bas_skus);
            return;
        }
        $commodities=$this->service->getByWms($this->bas_skus);
        if ($commodities) {
            $this->assertNotNull($commodities);
        }else{
            $this->assertNull($commodities);
        }
    }


    public function tearDown(): void
    {
        parent::tearDown(); // TODO: Change the autogenerated stub
    }
}
