CaiWuXiTong/tests/Feature/Business/PromotionMarketingAccountBillsTest.php
qiuxiang 1e90d55ca1 feat: 接入七平台推广费店铺明细
聚合淘系支付宝、阿里巴巴、拼多多、京东京准通、抖音千川、得物推广和唯品会推广流水的支出数据;统一店铺名称、交易时间、备注和支出金额字段,并按日期直方图分页,避免整批读取大流水。
2026-10-27 17:45:53 +08:00

114 lines
4.6 KiB
PHP

<?php
namespace Tests\Feature\Business;
use Mockery;
use Modules\EcommerceFinance\Repositories\PromotionMarketingExpenseRepository;
use Tests\Feature\FeatureTestCase;
class PromotionMarketingAccountBillsTest extends FeatureTestCase
{
public function test_promotion_marketing_tab_is_next_to_vipshop_jx(): void
{
$pages = collect(config('business_navigation'))
->firstWhere('slug', 'billing-transactions')['pages'];
$tabs = collect($pages)->firstWhere('slug', 'store-receiving-bills')['tabs'];
$slugs = array_column($tabs, 'slug');
$vipshopJxIndex = array_search('vipshop-jx', $slugs, true);
$this->assertNotFalse($vipshopJxIndex);
$this->assertSame('promotion-marketing', $slugs[$vipshopJxIndex + 1] ?? null);
$this->assertSame('推广费(营销账户)', $tabs[$vipshopJxIndex + 1]['title'] ?? null);
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'billing-transactions',
'page' => 'store-receiving-bills',
'tab' => 'promotion-marketing',
]))
->assertOk()
->assertSeeText('推广费(营销账户)');
}
public function test_promotion_marketing_page_and_details_share_contract(): void
{
$repository = Mockery::mock(PromotionMarketingExpenseRepository::class);
$result = [
'rows' => [[
'id' => 'row-1',
'store_name' => '测试推广店',
'occurred_at' => '2026-10-23 09:00:00',
'notes' => '商品推广',
'expense' => 12.34,
]],
'total' => 1,
'current_page' => 1,
'last_page' => 1,
'per_page' => 20,
'summary' => ['expense' => 12.34, 'count' => 1],
];
$repository->shouldReceive('paginate')->once()->ordered()->with([
'start' => '',
'end' => '',
'store_name' => '',
], 1, 10)->andReturn($result);
$repository->shouldReceive('paginate')->once()->ordered()->with([
'start' => '2026-10-01',
'end' => '2026-10-31',
'store_name' => '',
], 1, 20)->andReturn($result);
$this->app->instance(PromotionMarketingExpenseRepository::class, $repository);
$this->loginAs()
->getJson(route('ecommerce-finance.account-bills.index', [
'bill_type' => 'promotion-marketing',
]))
->assertOk()
->assertJsonPath('total', 1)
->assertJsonPath('summary.expense', 12.34)
->assertJsonPath('columns.title', '推广费(营销账户)')
->assertJsonPath('data.0.store_name', '测试推广店')
->assertJsonPath('columns.columns.0.label', '店铺名称')
->assertJsonPath('columns.columns.1.label', '交易时间')
->assertJsonPath('columns.columns.2.label', '备注')
->assertJsonPath('columns.columns.3.label', '支出金额');
$this->loginAs()
->getJson(route('ecommerce-finance.account-bills.promotion-expense-details', [
'bill_type' => 'promotion-marketing',
'start' => '2026-10-01',
'end' => '2026-10-31',
]))
->assertOk()
->assertJsonPath('total', 1)
->assertJsonPath('summary.expense', 12.34)
->assertJsonPath('summary.count', 1)
->assertJsonPath('data.0.notes', '商品推广')
->assertJsonPath('columns.0.field', 'store_name')
->assertJsonPath('columns.1.field', 'occurred_at')
->assertJsonPath('columns.2.field', 'notes')
->assertJsonPath('columns.3.field', 'expense');
}
public function test_promotion_marketing_store_options_come_from_the_same_date_range(): void
{
$repository = Mockery::mock(PromotionMarketingExpenseRepository::class);
$repository->shouldReceive('storeOptions')->once()->with([
'start' => '2026-10-01',
'end' => '2026-10-31',
'store_name' => '',
])->andReturn(['测试推广店', '另一推广店']);
$this->app->instance(PromotionMarketingExpenseRepository::class, $repository);
$this->loginAs()
->getJson(route('ecommerce-finance.account-bills.filter-options', [
'bill_type' => 'promotion-marketing',
'start' => '2026-10-01',
'end' => '2026-10-31',
]))
->assertOk()
->assertJsonPath('shops.0', '测试推广店')
->assertJsonPath('shops.1', '另一推广店');
}
}