<?php

namespace Tests\Services\OrderService;

use App\OracleDOCOrderHeader;
use App\Order;
use App\Services\OrderService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class GetByWmsOrdersTest extends TestCase
{
    /**
     * @var OrderService $service
     */
    private $service;
    private $data = [];

    protected function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated
        $this->service = app('OrderService');
        $orders = factory(Order::class)->times(1000)->create();
        $orderHeaders = collect();
        foreach ($orders as $order) {
            $orderHeader = factory(OracleDOCOrderHeader::class)->make(['orderno'=>$order->code]);
            $orderHeaders->push($orderHeader);
        }
        $this->data =[
            'orders' => $orders,
            'orderHeaders' => $orderHeaders
        ];
    }

    /**
     * @test
     */
    public function getByWmsOrders()
    {
        $orders = $this->service->getByWmsOrders($this->data['orderHeaders']);
        $this->assertNotEmpty($orders);
        $this->assertEquals(count($this->data['orders']),$orders->count());
    }

    protected function tearDown(): void
    {
        Order::query()->whereIn('id',data_get($this->data['orders'],'*.id'))->delete();
        parent::tearDown(); // TODO: Change the autogenerated stub
    }


}
