实际修改: - 店铺维度报表新增真实数据库条件查询:店铺字段走共享镜像 SQL WHERE,主体/能否变更/生效/失效走生命周期行级过滤(左闭右开) - 店铺负责人/部门负责人/利润中心改为店铺账号 PostgreSQL 镜像值, 按店铺名称关联,未匹配时回退经营分析副本库原值 - 能否变更按主表 platform 判定(唯品会MP/淘工厂=否,其余=是), 筛选改为 是/否 下拉;默认生效时间 2026-07-01,失效未记录显示存续中 - 主体维度经营报表接入生命周期收入窗口与注册地址解析市字段 - 同步更新视图测试并重写 StoreReportRepositoryTest 匹配 SQLite 实现 验证:容器内 tests/Feature/Business + tests/Unit/EcommerceFinance + tests/Unit/Business 共 324 passed / 4 skipped;真实数据端到端验证 (无筛选 1935 行、负责人/利润中心/失效区间筛选抽样全对)。 无新增数据库迁移,不涉及生产数据写入。
80 lines
3.2 KiB
PHP
80 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Modules\EcommerceFinance\Repositories\GenericBusinessMirrorRepository;
|
|
use Modules\EcommerceFinance\Repositories\StoreAccountMirrorRepository;
|
|
use Modules\EcommerceFinance\Services\BusinessMirrorDatasetRegistry;
|
|
use Tests\TestCase;
|
|
|
|
class StoreAccountMirrorRepositoryTest extends TestCase
|
|
{
|
|
private StoreAccountMirrorRepository $repository;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
config([
|
|
'database.connections.business_mirror' => [
|
|
'driver' => 'sqlite',
|
|
'database' => ':memory:',
|
|
'prefix' => '',
|
|
],
|
|
'upstream_mirrors.connection' => 'business_mirror',
|
|
'upstream_mirrors.datasets' => [
|
|
StoreAccountMirrorRepository::DATASET => [
|
|
'source_key' => 'database_4',
|
|
'schema' => 'external_store_accounts',
|
|
'object' => 'accounts_v1',
|
|
'target' => 'store_accounts',
|
|
'keys' => ['id'],
|
|
],
|
|
],
|
|
]);
|
|
DB::purge('business_mirror');
|
|
|
|
Schema::connection('business_mirror')->create('business_mirror_table_states', function (Blueprint $table): void {
|
|
$table->string('dataset_key')->primary();
|
|
$table->dateTime('initial_completed_at')->nullable();
|
|
});
|
|
Schema::connection('business_mirror')->create('store_accounts', function (Blueprint $table): void {
|
|
$table->string('id')->primary();
|
|
foreach (['storeName', 'operationOwner', 'operationDepartmentHead', 'operationDirector', 'profitCenter', 'accountType', 'account', 'boundPhone', 'verificationContact', 'accountGroupName', 'createdAt', 'updatedAt'] as $column) {
|
|
$table->string($column)->nullable();
|
|
}
|
|
});
|
|
DB::connection('business_mirror')->table('business_mirror_table_states')->insert([
|
|
'dataset_key' => StoreAccountMirrorRepository::DATASET,
|
|
'initial_completed_at' => '2026-09-04 10:00:00',
|
|
]);
|
|
|
|
$this->repository = new StoreAccountMirrorRepository(
|
|
new BusinessMirrorDatasetRegistry(),
|
|
new GenericBusinessMirrorRepository(app('db')),
|
|
);
|
|
}
|
|
|
|
public function test_it_maps_account_type_codes_to_business_labels(): void
|
|
{
|
|
foreach (['MAIN' => '主账号', 'SUB' => '子账号', '/' => null] as $type => $expected) {
|
|
DB::connection('business_mirror')->table('store_accounts')->insert([
|
|
'id' => 'account-' . md5($type),
|
|
'storeName' => '测试店铺',
|
|
'accountType' => $type,
|
|
'account' => 'test-account',
|
|
]);
|
|
}
|
|
|
|
$rows = collect($this->repository->paginate(1, 50)['data'])->keyBy('id');
|
|
|
|
$this->assertSame('主账号', $rows['account-' . md5('MAIN')]['account_type']);
|
|
$this->assertSame('子账号', $rows['account-' . md5('SUB')]['account_type']);
|
|
$this->assertNull($rows['account-' . md5('/')]['account_type']);
|
|
$this->assertNull($rows['account-' . md5('MAIN')]['password_configured']);
|
|
}
|
|
}
|