135 lines
5.0 KiB
PHP
135 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use App\Models\Auth\Permission;
|
|
use Mockery;
|
|
use Modules\EcommerceFinance\Services\StoreReceivingBalanceOverviewService;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class StoreReceivingBalanceOverviewEndpointTest extends FeatureTestCase
|
|
{
|
|
public function test_overview_endpoint_returns_the_selected_month_payload(): void
|
|
{
|
|
$this->user->attachPermission(
|
|
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
|
);
|
|
|
|
$payload = [
|
|
'month' => '2026-10',
|
|
'period' => ['start' => '2026-10-01', 'end' => '2026-10-31'],
|
|
'summary' => [
|
|
'opening_balance' => 100.0,
|
|
'income' => 30.0,
|
|
'expense' => 10.0,
|
|
'balance' => 120.0,
|
|
'platform_count' => 8,
|
|
'available_platform_count' => 8,
|
|
'complete' => true,
|
|
],
|
|
'platforms' => [],
|
|
];
|
|
$service = Mockery::mock(StoreReceivingBalanceOverviewService::class);
|
|
$service->shouldReceive('overview')->once()->with('2026-10')->andReturn($payload);
|
|
$this->app->instance(StoreReceivingBalanceOverviewService::class, $service);
|
|
|
|
$this->loginAs()
|
|
->getJson(route('ecommerce-finance.account-bills.overview', ['month' => '2026-10']))
|
|
->assertOk()
|
|
->assertJsonPath('month', '2026-10')
|
|
->assertJsonPath('summary.balance', 120)
|
|
->assertJsonPath('summary.complete', true);
|
|
}
|
|
|
|
public function test_overview_page_uses_the_vue_mount_point(): void
|
|
{
|
|
$this->user->attachPermission(
|
|
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
|
);
|
|
|
|
$this->loginAs()
|
|
->get(route('business.pages.show', [
|
|
'section' => 'billing-transactions',
|
|
'page' => 'store-receiving-bills',
|
|
'tab' => 'balance-overview',
|
|
]))
|
|
->assertOk()
|
|
->assertSee('class="biz-card mt-6 business-blank-page"', false)
|
|
->assertSee('public/js/business/pages.min.js', false);
|
|
}
|
|
|
|
public function test_income_detail_endpoint_returns_platform_store_and_bill_item_rows(): void
|
|
{
|
|
$this->user->attachPermission(
|
|
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
|
);
|
|
|
|
$payload = [
|
|
'month' => '2026-10',
|
|
'period' => ['start' => '2026-10-01', 'end' => '2026-10-31'],
|
|
'summary' => [
|
|
'income' => 120.0,
|
|
'platform_count' => 8,
|
|
'available_platform_count' => 8,
|
|
'complete' => true,
|
|
],
|
|
'details' => [[
|
|
'platform_slug' => 'taobao-alipay',
|
|
'platform' => '淘系支付宝账户',
|
|
'store_name' => '测试店铺',
|
|
'bill_item' => '货款收入',
|
|
'amount' => 120.0,
|
|
]],
|
|
];
|
|
$service = Mockery::mock(StoreReceivingBalanceOverviewService::class);
|
|
$service->shouldReceive('incomeDetail')->once()->with('2026-10')->andReturn($payload);
|
|
$this->app->instance(StoreReceivingBalanceOverviewService::class, $service);
|
|
|
|
$this->loginAs()
|
|
->getJson(route('ecommerce-finance.account-bills.overview.income-detail', [
|
|
'month' => '2026-10',
|
|
]))
|
|
->assertOk()
|
|
->assertJsonPath('summary.income', 120)
|
|
->assertJsonPath('details.0.platform_slug', 'taobao-alipay')
|
|
->assertJsonPath('details.0.bill_item', '货款收入');
|
|
}
|
|
|
|
public function test_expense_detail_endpoint_returns_platform_store_and_bill_item_rows(): void
|
|
{
|
|
$this->user->attachPermission(
|
|
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
|
);
|
|
|
|
$payload = [
|
|
'month' => '2026-10',
|
|
'period' => ['start' => '2026-10-01', 'end' => '2026-10-31'],
|
|
'summary' => [
|
|
'expense' => 88.0,
|
|
'platform_count' => 8,
|
|
'available_platform_count' => 8,
|
|
'complete' => true,
|
|
],
|
|
'details' => [[
|
|
'platform_slug' => 'jd-wallet',
|
|
'platform' => '京东网银钱包账户',
|
|
'store_name' => '测试店铺',
|
|
'bill_item' => '平台扣费',
|
|
'amount' => 88.0,
|
|
]],
|
|
];
|
|
$service = Mockery::mock(StoreReceivingBalanceOverviewService::class);
|
|
$service->shouldReceive('expenseDetail')->once()->with('2026-10')->andReturn($payload);
|
|
$this->app->instance(StoreReceivingBalanceOverviewService::class, $service);
|
|
|
|
$this->loginAs()
|
|
->getJson(route('ecommerce-finance.account-bills.overview.expense-detail', [
|
|
'month' => '2026-10',
|
|
]))
|
|
->assertOk()
|
|
->assertJsonPath('summary.expense', 88)
|
|
->assertJsonPath('details.0.platform_slug', 'jd-wallet')
|
|
->assertJsonPath('details.0.bill_item', '平台扣费');
|
|
}
|
|
}
|