CaiWuXiTong/tests/Feature/Business/MarketingAccountBillsTabsTest.php
WuYongJie 28a62434d2 整合并修正京东钱包账单 (#26)
接入京东充值与消耗账单,修复快照冷启动、刷新依赖、日期边界与标签局部切换。
2026-08-11 12:22:41 +08:00

134 lines
4.7 KiB
PHP

<?php
namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use Mockery;
use Modules\EcommerceFinance\Repositories\JdWalletBillRepository;
use Modules\EcommerceFinance\Services\UpstreamQueryCache;
use Modules\EcommerceFinance\Services\UpstreamQueryCacheFactory;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
use Tests\Feature\FeatureTestCase;
class MarketingAccountBillsTabsTest extends FeatureTestCase
{
public function testMarketingAccountBillsOnlyRenamesTheRequestedTabs(): void
{
$this->allowMarketingAccountBillsPage();
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'billing-transactions',
'page' => 'marketing-account-bills',
'tab' => 'taobao-wechat',
]))
->assertOk()
->assertSeeText('淘系支付宝账户')
->assertSeeText('Alibaba')
->assertSeeText('京东')
->assertDontSeeText('淘系微信账户')
->assertDontSeeText('京东网银钱包账户')
->assertSee('class="my-6 business-page--marketing-account-bills"', false);
}
public function testJdWalletHasRechargeAndConsumptionViewsWithoutChangingTheDataSource(): void
{
$this->allowMarketingAccountBillsPage();
$base = [
'section' => 'billing-transactions',
'page' => 'marketing-account-bills',
'tab' => 'jd-wallet',
];
$this->loginAs()
->get(route('business.pages.show', $base))
->assertOk()
->assertSeeText('充值账单')
->assertSeeText('消耗账单')
->assertSeeText('金额(元)')
->assertSeeText('充值时间')
->assertDontSeeText('投放日期')
->assertSee('data-jd-wallet-panel', false)
->assertSee('data-jd-wallet-navigation', false);
$this->loginAs()
->get(route('business.pages.show', array_merge($base, ['jd_ledger' => 'consumption'])))
->assertOk()
->assertSeeText('充值账单')
->assertSeeText('消耗账单')
->assertSeeText('金额(元)')
->assertSeeText('投放日期')
->assertSeeText('结算日期')
->assertDontSeeText('充值时间');
}
public function testJdWalletColdStartRegistersEveryRequiredSnapshotScope(): void
{
$this->allowMarketingAccountBillsPage();
$scopes = [];
$cache = Mockery::mock(UpstreamQueryCache::class);
$cache->shouldReceive('remember')
->times(3)
->andReturnUsing(function (string $scope, array $parameters, callable $resolver) use (&$scopes): array {
$scopes[] = $scope;
if (count($scopes) === 1) {
throw new ServiceUnavailableHttpException(30, '首份共享快照正在准备。');
}
return match ($scope) {
'jd-wallet-bills.recharge.summary' => [
'amount_total' => 0,
'balance_total' => 0,
'count' => 0,
],
'jd-wallet-bills.options' => [],
default => ['rows' => [], 'total' => 0],
};
});
$factory = Mockery::mock(UpstreamQueryCacheFactory::class);
$factory->shouldReceive('forSource')
->once()
->with('jiansun')
->andReturn($cache);
$this->app->instance(UpstreamQueryCacheFactory::class, $factory);
$this->app->instance(JdWalletBillRepository::class, Mockery::mock(JdWalletBillRepository::class));
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'billing-transactions',
'page' => 'marketing-account-bills',
'tab' => 'jd-wallet',
]))
->assertOk()
->assertSeeText('首份共享快照正在准备。');
$this->assertSame([
'jd-wallet-bills.recharge.list',
'jd-wallet-bills.recharge.summary',
'jd-wallet-bills.options',
], $scopes);
}
private function allowMarketingAccountBillsPage(): void
{
$this->user->update(['locale' => 'zh-CN']);
$this->user->attachPermission(
Permission::where('name', 'read-admin-panel')->firstOrFail()
);
$subject = 'user_' . $this->user->id;
setting()->set('system.sidebar_permissions', json_encode([
'configured' => [$subject],
'subjects' => [
$subject => ['billing-transactions/marketing-account-bills'],
],
], JSON_UNESCAPED_UNICODE));
}
}