<?php

namespace Tests\Services\OrderPackageReceivedSyncService;
use App\OrderPackage;
use App\Services\OrderPackageReceivedSyncService;
use Carbon\Carbon;
use Tests\TestCase;

class TestSyncLogisticRouteApi extends TestCase
{
    protected $order_package_ids;

    /** @var OrderPackageReceivedSyncService $service */
    public $service;
    function setUp(): void
    {
        parent::setUp();
        $this->service = app('OrderPackageReceivedSyncService');
    }

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

    function tearDown(): void
    {
        OrderPackage::destroy($this->order_package_ids);
        parent::tearDown();
    }

    /**
     * @test 测试主动更新Api
     * @throws \Exception
     */
    public function testUpdate()
    {
        $orderPackage1 = factory(OrderPackage::class)->create(['logistic_number' => 'SF1306128321691', 'exception' => '否', 'received_at' => null,]);
//        $orderPackage2 = factory(OrderPackage::class)->create(['logistic_number' => 'SF1038651413847', 'exception' => '否', 'received_at' => null,]);
//        $orderPackage3 = factory(OrderPackage::class)->create(['logistic_number' => 'SF1038611050071', 'exception' => '否', 'received_at' => null,]);
//        $orderPackage4 = factory(OrderPackage::class)->create(['logistic_number' => '73228021907536', 'exception' => '否', 'received_at' => null,]);
//        $orderPackage5 = factory(OrderPackage::class)->create(['logistic_number' => '73228022816494', 'exception' => '否', 'received_at' => null,]);
        $this->order_package_ids [] = $orderPackage1->id;
//        $this->order_package_ids [] = $orderPackage2->id;
//        $this->order_package_ids [] = $orderPackage3->id;
//        $this->order_package_ids [] = $orderPackage4->id;
//        $this->order_package_ids [] = $orderPackage5->id;

        $this->service->syncLogisticRouteApi(['SF' => ['SF1306128321691']]);
//        $this->service->syncLogisticRouteApi(['ZTO' => ['73228021907536', '73228022816494']]);
//        dd(OrderPackage::query()->where('logistic_number','SF1306128321691')->get()->toArray());
        $this->assertDatabaseHas('order_packages',[
            'logistic_number' => 'SF1306128321691',
            'status' => '派送异常',
            'exception' => '是',
            "exception_type" => "派件异常"
        ]);
//        $this->assertDatabaseHas('order_packages',[
//            'logistic_number' => 'SF1038651413847',
//            'status' => '已收件',
//            'exception' => '否',
//        ]);
//        $this->assertDatabaseHas('order_packages',[
//            'logistic_number' => 'SF1038611050071',
//            'status' => '已收件',
//            'exception' => '否',
//        ]);
//        $this->assertDatabaseHas('order_packages',[
//            'logistic_number' => '73228021907536',
//            'status' => '已收件',
//            'exception' => '否',
//        ]);
//        $this->assertDatabaseHas('order_packages',[
//            'logistic_number' => '73228022816494',
//            'status' => '已收件',
//            'exception' => '否',
//        ]);
    }

    public function test_update_0021()
    {
        $this->service->syncLogisticRoute();
    }
}
