98 lines
4.1 KiB
PHP
98 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use App\Models\Auth\Permission;
|
|
use Mockery;
|
|
use Modules\EcommerceFinance\Repositories\CourierInformationMirrorRepository;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class CourierInformationPageTest extends FeatureTestCase
|
|
{
|
|
public function test_page_explains_when_courier_mirror_is_not_available(): void
|
|
{
|
|
$this->user->attachPermission(
|
|
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
|
);
|
|
|
|
$repository = Mockery::mock(CourierInformationMirrorRepository::class);
|
|
$repository->shouldReceive('relatedAvailability')->once()->andReturn([
|
|
'main' => false, 'networks' => false, 'accounts' => false,
|
|
'network_ready' => false, 'account_ready' => false,
|
|
]);
|
|
$repository->shouldReceive('available')->once()->andReturnFalse();
|
|
$repository->shouldNotReceive('state');
|
|
$repository->shouldNotReceive('syncStatus');
|
|
$repository->shouldNotReceive('ready');
|
|
$repository->shouldNotReceive('paginate');
|
|
$this->app->instance(CourierInformationMirrorRepository::class, $repository);
|
|
|
|
$this->loginAs()
|
|
->get(route('business.pages.show', [
|
|
'section' => 'courier-payables',
|
|
'page' => 'courier-information',
|
|
]))
|
|
->assertOk()
|
|
->assertSeeText('快递资料')
|
|
->assertSeeText('共享业务镜像尚未建立,快递资料暂时无法读取。')
|
|
->assertSeeText('网点')
|
|
->assertSeeText('打款信息')
|
|
->assertSeeText('操作日志');
|
|
}
|
|
|
|
public function test_page_renders_mirrored_courier_rows_and_filters(): void
|
|
{
|
|
$this->user->attachPermission(
|
|
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
|
);
|
|
|
|
$repository = Mockery::mock(CourierInformationMirrorRepository::class);
|
|
$repository->shouldReceive('relatedAvailability')->once()->andReturn([
|
|
'main' => true, 'networks' => false, 'accounts' => false,
|
|
'network_ready' => false, 'account_ready' => false,
|
|
]);
|
|
$repository->shouldReceive('available')->once()->andReturnTrue();
|
|
$repository->shouldReceive('state')->once()->andReturn([
|
|
'status' => 'succeeded',
|
|
'initial_completed_at' => '2026-08-28 10:00:00',
|
|
'last_succeeded_at' => '2026-08-28 10:00:00',
|
|
'mirror_row_count' => 1,
|
|
]);
|
|
$repository->shouldReceive('syncStatus')->once()->andReturn(['code' => 'healthy', 'lag_minutes' => 3]);
|
|
$repository->shouldReceive('ready')->once()->andReturnTrue();
|
|
$repository->shouldReceive('paginate')->once()->withArgs(function (array $filters, int $page, int $limit): bool {
|
|
return $filters['expcode'] === 'SF' && $filters['status'] === '1' && $page === 1 && $limit > 0;
|
|
})->andReturn([
|
|
'data' => [(object) [
|
|
'Id' => 1,
|
|
'expcode' => 'SF',
|
|
'expname' => '顺丰速运',
|
|
'status' => 1,
|
|
'tradebtime' => '2026-01-01 00:00:00',
|
|
]],
|
|
'total' => 1,
|
|
]);
|
|
$this->app->instance(CourierInformationMirrorRepository::class, $repository);
|
|
|
|
$response = $this->loginAs()
|
|
->get(route('business.pages.show', [
|
|
'section' => 'courier-payables',
|
|
'page' => 'courier-information',
|
|
'expcode' => 'SF',
|
|
'status' => '1',
|
|
]))
|
|
->assertOk()
|
|
->assertSeeText('顺丰速运')
|
|
->assertSeeText('SF')
|
|
->assertSeeText('同步正常')
|
|
->assertSeeText('可达服务')
|
|
->assertSeeText('第 1 / 1 页,本页 1 条,共 1 条')
|
|
->assertSee('name="expcode"', false);
|
|
|
|
$this->assertMatchesRegularExpression(
|
|
'/<div class="courier-information-table-panel">\s*<div class="courier-information-table-wrap">.*?<\/table>\s*<\/div>\s*<div class="courier-information-footer">/s',
|
|
$response->getContent()
|
|
);
|
|
}
|
|
}
|