user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); $connection = DB::connection('business_mirror'); $connection->table('fin_accounts')->insert([ ['company_name' => '店铺映射测试公司', 'account_short' => '映射账户甲'], ['company_name' => '店铺映射测试公司', 'account_short' => '映射账户乙'], ]); $connection->table('fin_shops')->insert([ ['shop_name' => '天猫-映射店铺甲', 'account_short' => '映射账户甲'], ['shop_name' => '天猫-映射店铺乙', 'account_short' => '映射账户乙'], ['shop_name' => '天猫-映射店铺丙', 'account_short' => '/'], ]); $connection->table('fin_account_map')->insert([ ['source' => 'shop', 'source_value' => '天猫-映射店铺甲', 'account_short' => null], ['source' => 'shop', 'source_value' => '天猫-映射店铺乙', 'account_short' => null], ['source' => 'shop', 'source_value' => '天猫-映射店铺丙', 'account_short' => null], ['source' => 'shop', 'source_value' => '已经映射的店铺', 'account_short' => '映射账户甲'], ]); } private function previewUrl(): string { return route('business.financial-ledger.mapping.shop.preview', [ 'company_id' => $this->company->id, ]); } private function applyUrl(): string { return route('business.financial-ledger.mapping.shop.apply', [ 'company_id' => $this->company->id, ]); } public function test_preview_and_apply_only_exact_shop_name_matches(): void { $this->loginAs()->postJson($this->previewUrl()) ->assertOk() ->assertJsonPath('total', 3) ->assertJsonPath('matched', 2) ->assertJsonPath('unmatched', 1) ->assertJsonCount(2, 'sample'); $this->assertDatabaseHas('fin_account_map', [ 'source' => 'shop', 'source_value' => '天猫-映射店铺甲', 'account_short' => null, ], 'business_mirror'); $this->loginAs()->postJson($this->applyUrl()) ->assertOk() ->assertJsonPath('mapped', 2) ->assertJsonPath('unmatched', 1); $this->assertDatabaseHas('fin_account_map', [ 'source' => 'shop', 'source_value' => '天猫-映射店铺甲', 'account_short' => '映射账户甲', 'updated_by' => 'Test User', ], 'business_mirror'); $this->assertDatabaseHas('fin_account_map', [ 'source' => 'shop', 'source_value' => '天猫-映射店铺乙', 'account_short' => '映射账户乙', ], 'business_mirror'); $this->assertDatabaseHas('fin_account_map', [ 'source' => 'shop', 'source_value' => '天猫-映射店铺丙', 'account_short' => null, ], 'business_mirror'); $this->assertDatabaseHas('fin_account_map', [ 'source' => 'shop', 'source_value' => '已经映射的店铺', 'account_short' => '映射账户甲', ], 'business_mirror'); $this->assertDatabaseCount('fin_account_map_events', 2, 'business_mirror'); } }