<?php

namespace Tests\Services\RejectedBillService;
use App\Order;
use App\OrderPackage;
use App\Services\RejectedBillService;
use Tests\TestCase;
use App\RejectedBill;
use App\Traits\TestMockSubServices;

class FindOrderByOrderPackageTest 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['OrderPackage']
            = factory(OrderPackage::class)
            ->create(['order_id'=>$this->data['Order']['id']]);
    }

    public function testReturned()
    {
        $logistic_number = $this->data['OrderPackage']['logistic_number'];
        $arr = $this->service->findOrderByOrderPackage($logistic_number);
        $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();
        OrderPackage::query()
            ->where('id',$this->data['OrderPackage']['id'] ?? '')
            ->delete();
        parent::tearDown();
    }
}
