<?php

namespace Tests\Services\RejectedBillService;
use App\Order;
use App\OrderIssue;
use App\OrderIssueRejectedBill;
use App\OrderPackage;
use App\Services\RejectedBillService;
use Illuminate\Support\Str;
use Tests\TestCase;
use App\RejectedBill;
use App\Traits\TestMockSubServices;

class FindOrderByOrderIssueTest extends TestCase
{
    use TestMockSubServices;
    /** @var RejectedBillService $service */
    public $service;
    private $data;
    private $amount=1;
    function setUp(): void
    {
        parent::setUp();
        $this->service = app('RejectedBillService');
        $this->data['Order']
            = factory(Order::class)
            ->create();
        $this->data['OrderIssue']
            = factory(OrderIssue::class)
            ->create(['order_id'=>$this->data['Order']->id]);
        $this->data['OrderIssueRejectedBill']
            = factory(OrderIssueRejectedBill::class)
            ->create(['order_issue_id' => $this->data['OrderIssue']['id'],'logistic_number_return' => Str::random(10)]);
    }

    public function testReturned()
    {
        $logistic_number_return = $this->data['OrderIssueRejectedBill']['logistic_number_return'];
        $arr = $this->service->findOrderByOrderIssue($logistic_number_return);
        $this->assertEquals($arr['logistic_id'],$this->data['Order']['logistic_id']);
        $this->assertEquals($arr['owner_id'],$this->data['Order']['owner_id']);
        $this->assertEquals($arr['consignee_name'],$this->data['Order']['consignee_name']);
        $this->assertEquals($arr['consignee_phone'],$this->data['Order']['consignee_phone']);
        $this->assertEquals($arr['client_code'],$this->data['Order']['client_code']);
    }

    function tearDown(): void
    {
        Order::query()->where('id',$this->data['Order']['id'])
            ->delete();
        OrderIssueRejectedBill::query()
            ->where('order_issue_id',$this->data['OrderIssue']['id'])
            ->where('logistic_number_return',$this->data['OrderIssueRejectedBill']['logistic_number_return'])
            ->delete();
        OrderIssue::query()->where('id',$this->data['OrderIssue']['id'])
            ->delete();
        parent::tearDown();
    }
}
