<?php

namespace Tests\Services\OracleDocOrderHeaderServie\GetWmsOrderOnStartDateEditTest;

use App\OracleDOCOrderHeader;
use App\OrderTrackingOwner;
use App\Owner;
use App\Services\OracleDOCOrderHeaderService;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class GetWmsOrderOnStartDateEditTest extends TestCase
{
    /** @var OracleDOCOrderHeaderService $service */
    public $service;

    public function setUp(): void
    {
        parent::setUp();
        $this->service = app(OracleDOCOrderHeaderService::class);
        factory(OrderTrackingOwner::class)->create([
            'owner_id'=>factory(Owner::class)->create(['user_owner_group_id'=>null,'code'=>'WANLING'])->id,
            'status'=>'启用']);
     }

    /**
     * @test
     */
    public function getWmsOrderOnStartDateEdit()
    {
        $orderHeader= OracleDOCOrderHeader::query()->where('CustomerID','WANLING')->orderByDesc('EditTime')->first();
        if(!$orderHeader){
            $this->assertNull($orderHeader);
            return ;
        }
        $carbon =Carbon::parse($orderHeader->addtime)->subMinutes(5);
        $orderHeaders = $this->service->getWmsOrderOnStartDateEdit($carbon);
        if(!$orderHeaders){
            $this->assertNull($orderHeaders);
            return ;
        }
        $this->assertNotNull($orderHeaders);
        $orderHeader = $orderHeaders->first();
        $this->assertNotNull($orderHeader->oracleDOCOrderDetails);
        $this->assertNotNull($orderHeader->actAllocationDetails);
        $this->assertNotNull($orderHeader->oracleBASCustomer);
        $this->assertNotNull($orderHeader->oracleBASCode);
    }
}
