提现管理主体跟随店铺维度报表最新存续期间。 PR #559 Co-authored-by: 92451 <924518135@qq.com> Co-committed-by: 92451 <924518135@qq.com>
84 lines
3.3 KiB
PHP
84 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use App\Business\StoreReceivingAccountSynchronizer;
|
|
use App\Models\Business\StoreReceivingAccount;
|
|
use Mockery;
|
|
use Modules\EcommerceFinance\Repositories\BusinessInformationMirrorRepository;
|
|
use Modules\EcommerceFinance\Services\StoreReportPeriodBuilder;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class StoreReceivingAccountSynchronizerTest extends FeatureTestCase
|
|
{
|
|
public function test_sync_uses_current_store_report_company_when_updating_account(): void
|
|
{
|
|
$storeName = '拼多多-百里香家具旗舰店';
|
|
$account = StoreReceivingAccount::query()->create([
|
|
'company_id' => $this->company->id,
|
|
'store_platform' => '拼多多',
|
|
'erp_store_name' => $storeName,
|
|
'shop_name' => $storeName,
|
|
'store_entity_name' => '历史旧主体',
|
|
]);
|
|
$source = [[
|
|
'id' => 701,
|
|
'store_id' => 'PDD-701',
|
|
'shop_name' => $storeName,
|
|
'erp_store_name' => $storeName,
|
|
'company_name' => '店铺基础信息旧主体',
|
|
'source_platform' => '拼多多',
|
|
'store_status' => '0',
|
|
'store_type' => 'POP',
|
|
]];
|
|
$mirror = Mockery::mock(BusinessInformationMirrorRepository::class);
|
|
$mirror->shouldReceive('receivingAccountStores')->once()->andReturn($source);
|
|
$periods = Mockery::mock(StoreReportPeriodBuilder::class);
|
|
$periods->shouldReceive('currentCompanies')
|
|
->once()
|
|
->with(Mockery::on(
|
|
static fn (array $stores): bool => $stores === [[
|
|
'erp_store_name' => $storeName,
|
|
'system_company_name' => '店铺基础信息旧主体',
|
|
]],
|
|
))
|
|
->andReturn([$storeName => '报表存续中主体']);
|
|
|
|
$result = (new StoreReceivingAccountSynchronizer($mirror, $periods))
|
|
->sync((int) $this->company->id);
|
|
|
|
$this->assertSame(1, $result['updated']);
|
|
$this->assertSame('报表存续中主体', $account->fresh()->store_entity_name);
|
|
}
|
|
|
|
public function test_sync_falls_back_to_store_information_company_when_no_current_period_exists(): void
|
|
{
|
|
$storeName = '天猫-无存续期主体店';
|
|
$source = [[
|
|
'id' => 702,
|
|
'store_id' => 'TM-702',
|
|
'shop_name' => $storeName,
|
|
'erp_store_name' => $storeName,
|
|
'company_name' => '店铺基础信息主体',
|
|
'source_platform' => '天猫',
|
|
'store_status' => '0',
|
|
'store_type' => '旗舰店',
|
|
]];
|
|
$mirror = Mockery::mock(BusinessInformationMirrorRepository::class);
|
|
$mirror->shouldReceive('receivingAccountStores')->once()->andReturn($source);
|
|
$periods = Mockery::mock(StoreReportPeriodBuilder::class);
|
|
$periods->shouldReceive('currentCompanies')->once()->andReturn([]);
|
|
|
|
(new StoreReceivingAccountSynchronizer($mirror, $periods))
|
|
->sync((int) $this->company->id);
|
|
|
|
$this->assertSame(
|
|
'店铺基础信息主体',
|
|
StoreReceivingAccount::withoutGlobalScopes()
|
|
->where('company_id', $this->company->id)
|
|
->where('store_name', $storeName)
|
|
->value('store_entity_name'),
|
|
);
|
|
}
|
|
}
|