<?php

namespace Tests\Services\OrderPackageReceivedSyncService;

use App\Order;
use App\OrderPackage;
use App\Services\OrderPackageReceivedSyncService;
use Tests\TestCase;
use App\Traits\TestMockSubServices;

class SetExceptionTypeTest extends TestCase
{
    use TestMockSubServices;

    /** @var OrderPackageReceivedSyncService $service */
    public $service;
    private $data;
    private $amount = 2;

    function setUp(): void
    {
        parent::setUp();
        $this->service = app('OrderPackageReceivedSyncService');
        $this->data['orderPackage'] = [];
        $this->data['order'] = [];
    }

    public function testReturned()
    {
        $this->assertTrue(true);
    }

    function tearDown(): void
    {
        OrderPackage::query()->whereIn('id', $this->data['orderPackage'])->delete();
        Order::query()->whereIn('id', $this->data['order'])->delete();
        parent::tearDown();
    }

    /**
     * @test
     */
    public function 超过24小时未揽件()
    {
        $order = factory(Order::class)->create();
        $orderPackage = factory(OrderPackage::class)->create([
            'order_id' => $order->id,
            'sent_at' => now()->subHours(25),
            "logistic_number" => 4314543143889
        ]);
        $this->data['orderPackage'][] = $orderPackage->id;
        $this->data['order'][] = $order->id;
        $data = [
            "logistic_number" => "4314543143889",
            "status" => "在途",
            "transfer_status" => [
                [
                    "accept_time" => "2021-05-17 19:34:34",
                    "accept_address" => "【上海市】上海松江区九亭公司 -张东东(18116299116) 已揽收",
                    "remark" => ""
                ],
                [
                    "accept_time" => "2021-05-18 00:14:26",
                    "accept_address" => "【上海市】已到达 上海分拨中心",
                    "remark" => "",
                ],
                [
                    "accept_time" => "2021-05-18 00:21:23",
                    "accept_address" => "【上海市】已离开 上海分拨中心，发往 浙江嘉兴分拨中心",
                    "remark" => "",
                ],
                [
                    "accept_time" => "2021-05-18 05:17:43",
                    "accept_address" => "【嘉兴市】已到达 浙江嘉兴分拨中心",
                    "remark" => "",
                ],
                [
                    "accept_time" => "2021-05-18 05:20:37",
                    "accept_address" => "【嘉兴市】已离开 浙江嘉兴分拨中心，发往 浙江嘉善县公司",
                    "remark" => "",
                ],
                [
                    "accept_time" => "2021-05-18 06:58:04",
                    "accept_address" => "【嘉兴市】已到达 浙江嘉善县公司",
                    "remark" => "",
                ],
                [
                    "accept_time" => "2021-05-18 07:47:29",
                    "accept_address" => "【嘉兴市】浙江嘉善县公司 快递员黄建林(17816502922) 正在为您派送。快件已消毒，小哥体温正常，将佩戴口罩为您派送，您也可联系小哥将快件放置指定代收点或快递柜，祝您身体健康【95121为韵达快递员外呼专属号码，请放心接听】",
                    "remark" => "",
                ],
                [
                    "accept_time" => "2021-05-18 12:04:50",
                    "accept_address" => "【代收点】您的快件已暂存至 金都上品游泳池旁丰巢柜3号柜 保管，地址：金都上品游泳池旁丰巢柜3号柜，请及时领取，如有疑问请电联快递员:黄建林(17816502922)，投诉电话:0571-28914641",
                    "remark" => "",
                ],
            ],
            "exception_type" => null,
            "exception" => null,
            "routes_length" => 1,
        ];
        $result = $this->service->setExceptionType($data, $data['transfer_status'][count($data['transfer_status']) - 1]['accept_time']);
        $this->assertEquals('派件异常', $result['exception_type']);
    }
}
