<?php

namespace Tests\Services\ShopService;

use App\OracleDOCOrderHeader;
use App\Owner;
use App\Services\OwnerService;
use App\Services\ShopService;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class GetShopByCodeMapTest extends TestCase
{
    /** @var OwnerService $service */
    private $service;
    private $data;

    public function setUp(): void
    {
        parent::setUp(); // TODO: Change the autogenerated stub

        $this->service = app('ShopService');

        $this->data = [];

        $orderHeader = OracleDOCOrderHeader::query()
            ->whereNotNull('issuepartyname')
            ->where('sostatus','99')
            ->orderByDesc('AddTime')
            ->first();

        $this->data['orderHeader'] = $orderHeader;
        $this->data['map'][] = [
            'owner_code' => $orderHeader['customerid'],
            'issuepartyname' => $orderHeader['issuepartyname']
        ];
    }

    /**
     * @test
     */
    public function getShopByCodeMap()
    {
        $shop =  $this->service->getShopByCodeMap($this->data['map']);
        $this->assertNotNull($shop);
        $orderHeader = $this->data['orderHeader'];
        $owner = Owner::find($shop->first()->owner_id);
        $this->assertEquals($owner->code,$orderHeader['customerid']);
        $this->assertEquals($shop->first()->name,$orderHeader['issuepartyname']);
    }

    public function tearDown(): void
    {
        cache()->flush();
        parent::tearDown(); // TODO: Change the autogenerated stub
    }
}
