CaiWuXiTong/tests/Feature/Business/DewuAlipayReceivingBillsTest.php
qiuxiang 1a592c82a0 feat(得物支付宝账户): 增加店铺与商户号映射列 (#1373)
新增支付宝账户、得物店铺和商户号映射列。
2026-11-24 14:41:21 +08:00

105 lines
4.1 KiB
PHP

<?php
namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use Mockery;
use Modules\EcommerceFinance\Repositories\StoreReceivingDewuAlipayBillMirrorRepository;
use Tests\Feature\FeatureTestCase;
class DewuAlipayReceivingBillsTest extends FeatureTestCase
{
public function test_endpoint_reads_only_the_scoped_dewu_alipay_mirror(): void
{
$this->allowPage();
$repository = Mockery::mock(StoreReceivingDewuAlipayBillMirrorRepository::class);
$repository->shouldReceive('paginate')
->once()
->with(
Mockery::on(static fn (array $filters): bool => ($filters['start'] ?? null) === '2026-10-01'
&& ($filters['end'] ?? null) === '2026-10-31'),
'occurred_at',
'desc',
1,
20,
)
->andReturn([
'data' => [[
'record_code' => '2000000001360000001',
'store_name' => '支付宝-常州阔之煜家居有限公司',
'bill_item' => '商家代付货款',
'alipay_account' => '2088841085257651',
'occurred_at' => '2026-10-27 18:52:15',
'income' => 21815.89,
'expense' => 0,
'balance' => 92957.40,
]],
'total' => 1,
'current_page' => 1,
'last_page' => 1,
'per_page' => 20,
'summary' => [
'income' => 21815.89,
'expense' => 0,
'opening_balance' => 71141.51,
'opening_balance_date' => '2026-09-30',
'opening_balance_source' => 'previous_period',
'balance' => 92957.40,
'count' => 1,
],
'sync' => ['status' => 'succeeded', 'last_succeeded_at' => '2026-11-01 09:00:00'],
]);
$this->app->instance(StoreReceivingDewuAlipayBillMirrorRepository::class, $repository);
$response = $this->loginAs()
->getJson(route('ecommerce-finance.account-bills.index', [
'bill_type' => 'dewu-alipay',
'start' => '2026-10-01',
'end' => '2026-10-31',
'limit' => 20,
]))
->assertOk()
->assertJsonPath('columns.title', '得物支付宝账户')
->assertJsonPath('total', 1)
->assertJsonPath('data.0.alipay_account', '2088841085257651')
->assertJsonPath('summary.balance', 92957.4);
$columnLabels = array_column($response->json('columns.columns'), 'label');
$actualStoreIndex = array_search('线上单号对应实际店铺', $columnLabels, true);
$this->assertSame(
['支付宝账户名', '得物店铺', '商户号'],
array_slice($columnLabels, $actualStoreIndex + 1, 3),
);
}
public function test_filter_options_expose_the_eight_scoped_accounts(): void
{
$this->allowPage();
$repository = Mockery::mock(StoreReceivingDewuAlipayBillMirrorRepository::class);
$repository->shouldReceive('filterOptions')->once()->andReturn([
'shops' => StoreReceivingDewuAlipayBillMirrorRepository::STORE_NAMES,
'bill_items' => ['商家代付货款', '技术服务费'],
]);
$this->app->instance(StoreReceivingDewuAlipayBillMirrorRepository::class, $repository);
$response = $this->loginAs()
->getJson(route('ecommerce-finance.account-bills.filter-options', [
'bill_type' => 'dewu-alipay',
]))
->assertOk()
->assertJsonPath('bill_items.1', '技术服务费')
->assertJsonCount(8, 'shops');
$this->assertContains(
'支付宝-常州春之华家居有限公司',
$response->json('shops'),
);
}
private function allowPage(): void
{
$this->user->attachPermission(
Permission::where('name', 'read-admin-panel')->firstOrFail(),
);
}
}