<?php

namespace Tests\Services\OrderService\GetByWmsOrdersTest;

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 */
    public $service;

    public function setUp(): void
    {
        parent::setUp();
        $this->service = app('OrderService');
    }

    public function testGetByWmsOrders()
    {
        $orders = Order::query()->orderByDesc('id')->forPage(0,5)->get();
        $orderHeader = OracleDOCOrderHeader::query()->whereIn('OrderNo',$orders->map(function($order){
            return $order->code;
        }))->get();
        $order_list = $this->service->getByWmsOrders($orderHeader);
        $this->assertIsBool(count($order_list)==count($orders));

        $order_codes = $orders->sortBy('code')->map(function($order){
            return $order->code;
        });

        $order_list_codes = $order_list->sortBy('code')->map(function($order){
            return $order->code;
        });

        $this->assertEquals(count($order_list_codes),count($order_codes));
    }
}
