80 lines
2.9 KiB
PHP
80 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Modules\EcommerceFinance\Services\AccountMappingSuggestion;
|
|
use Tests\TestCase;
|
|
|
|
class AccountMappingSuggestionTest extends TestCase
|
|
{
|
|
public function test_same_bill_item_on_another_platform_fills_the_mapping_template(): void
|
|
{
|
|
$result = app(AccountMappingSuggestion::class)->suggestFromRules([
|
|
$this->rule('京喜', 'POP商家激励金', '优惠收入', '收入'),
|
|
], '京东', 'POP商家激励金');
|
|
|
|
$this->assertTrue($result['auto_fill']);
|
|
$this->assertSame('same_item', $result['reason']);
|
|
$this->assertSame('优惠收入', $result['values']['memo']);
|
|
$this->assertSame('收入', $result['values']['category']);
|
|
$this->assertSame('京喜', $result['sources'][0]['platform']);
|
|
}
|
|
|
|
public function test_item_normalization_ignores_wx_prefix_spaces_and_punctuation(): void
|
|
{
|
|
$result = app(AccountMappingSuggestion::class)->suggestFromRules([
|
|
$this->rule('淘宝', '淘宝新品礼金技术服务费', '冲减收入', '收入'),
|
|
], '天猫', 'wx 淘宝新品礼金技术服务费');
|
|
|
|
$this->assertTrue($result['auto_fill']);
|
|
$this->assertSame('冲减收入', $result['values']['memo']);
|
|
}
|
|
|
|
public function test_conflicting_templates_are_not_applied_automatically(): void
|
|
{
|
|
$result = app(AccountMappingSuggestion::class)->suggestFromRules([
|
|
$this->rule('淘宝', '服务费', '优惠收入', '收入'),
|
|
$this->rule('天猫', '服务费', '平台服务费', '平台服务费', '销售费用'),
|
|
], '京东', '服务费');
|
|
|
|
$this->assertFalse($result['auto_fill']);
|
|
$this->assertSame('ambiguous_templates', $result['reason']);
|
|
$this->assertSame([], $result['values']);
|
|
}
|
|
|
|
public function test_no_same_name_rule_returns_an_empty_suggestion(): void
|
|
{
|
|
$result = app(AccountMappingSuggestion::class)->suggestFromRules([
|
|
$this->rule('淘宝', '服务费', '平台服务费', '平台服务费'),
|
|
], '京东', '返利框架费');
|
|
|
|
$this->assertFalse($result['auto_fill']);
|
|
$this->assertSame('no_same_item', $result['reason']);
|
|
}
|
|
|
|
/** @return array<string,mixed> */
|
|
private function rule(
|
|
string $platform,
|
|
string $item,
|
|
string $memo,
|
|
string $category,
|
|
string $dAcct = '其他货币资金',
|
|
): array {
|
|
return [
|
|
'id' => 1,
|
|
'platform' => $platform,
|
|
'item' => $item,
|
|
'memo' => $memo,
|
|
'goods' => '',
|
|
'invoice' => '-',
|
|
'category' => $category,
|
|
'feeMemo' => '',
|
|
'dAcct' => $dAcct,
|
|
'dSub' => '',
|
|
'cAcct' => '主营业务收入',
|
|
'cSub' => '',
|
|
'basis' => in_array($category, ['收入', '往来', '转账'], true) ? '收入基准' : '支出基准',
|
|
];
|
|
}
|
|
}
|