CaiWuXiTong/tests/Feature/Business/FinanceLedgerShopDirectoryTest.php
92451 e08d578b5d 兼容店铺余额名称前缀匹配 (#650)
Co-authored-by: 92451 <924518135@qq.com>
Co-committed-by: 92451 <924518135@qq.com>
2026-10-26 20:40:53 +08:00

105 lines
3.5 KiB
PHP

<?php
namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use Illuminate\Support\Facades\DB;
use Modules\EcommerceFinance\Repositories\BusinessInformationMirrorRepository;
use Modules\EcommerceFinance\Services\StoreReportPeriodBuilder;
use Tests\Feature\FeatureTestCase;
class FinanceLedgerShopDirectoryTest extends FeatureTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->user->attachPermission(
Permission::where('name', 'read-admin-panel')->firstOrFail(),
);
}
public function test_shop_ledger_uses_store_report_current_subject_and_platform(): void
{
DB::connection('business_mirror')->table('fin_shops')->insert([
'shop_name' => '报表测试店',
'platform' => '天猫',
'shop_balance' => 123.45,
'shop_balance_date' => '2026-10-25',
'created_at' => now(),
'updated_at' => now(),
]);
$openStore = [
'id' => 901,
'platform' => '天猫',
'erp_store_name' => '天猫-报表测试店',
'company_name' => '历史主体',
'store_status' => '0',
'withdrawal_account' => '回款账户甲',
];
$closedStore = [
'id' => 902,
'platform' => '京东',
'erp_store_name' => '京东-已关店',
'company_name' => '历史主体',
'store_status' => '6',
'withdrawal_account' => null,
];
$openStoreWithoutSubject = [
'id' => 903,
'platform' => '淘宝',
'erp_store_name' => '淘宝-无主体店',
'company_name' => null,
'store_status' => '0',
'withdrawal_account' => null,
];
$this->mock(BusinessInformationMirrorRepository::class)
->shouldReceive('allStores')
->once()
->andReturn([$openStore, $closedStore, $openStoreWithoutSubject]);
$this->mock(StoreReportPeriodBuilder::class)
->shouldReceive('build')
->once()
->with([$openStore, $openStoreWithoutSubject])
->andReturn([
'天猫-报表测试店' => [
[
'company_name' => '历史主体',
'effective_at' => '2026-07-01',
'expires_at' => '2026-10-01',
'source' => 'initial',
],
[
'company_name' => '当前存续主体',
'effective_at' => '2026-10-02',
'expires_at' => null,
'source' => 'crawl',
],
],
]);
$this->loginAs()->get($this->pageUrl())
->assertOk()
->assertSeeText('天猫')
->assertSeeText('天猫-报表测试店')
->assertSeeText('当前存续主体')
->assertSeeText('淘宝-无主体店')
->assertSeeText('在营')
->assertSeeText('回款账户甲')
->assertSeeText('123.45')
->assertDontSeeText('京东-已关店')
->assertDontSeeText('历史主体');
}
private function pageUrl(): string
{
return route('business.pages.show', [
'company_id' => $this->company->id,
'section' => 'financial-operations',
'page' => 'ledger',
]);
}
}