64 lines
2.0 KiB
PHP
64 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Modules\EcommerceFinance\Services\AccountMappingResyncDispatcher;
|
|
use ReflectionClass;
|
|
use Tests\TestCase;
|
|
|
|
class AccountMappingResyncDispatcherTest extends TestCase
|
|
{
|
|
public function test_production_leaves_queue_processing_to_the_limited_batch_worker(): void
|
|
{
|
|
config(['upstream_pipeline.batch_worker_enabled' => true]);
|
|
$dispatcher = $this->recordingDispatcher();
|
|
$dispatcher->spawnWorker();
|
|
|
|
$this->assertSame(0, $dispatcher->launches);
|
|
}
|
|
|
|
public function test_local_development_still_launches_an_immediate_worker(): void
|
|
{
|
|
config(['upstream_pipeline.batch_worker_enabled' => false]);
|
|
$dispatcher = $this->recordingDispatcher();
|
|
$dispatcher->spawnWorker();
|
|
|
|
$this->assertSame(1, $dispatcher->launches);
|
|
}
|
|
|
|
private function recordingDispatcher(): AccountMappingResyncDispatcher
|
|
{
|
|
return new class extends AccountMappingResyncDispatcher {
|
|
public int $launches = 0;
|
|
|
|
protected function launchWorker(): void
|
|
{
|
|
$this->launches++;
|
|
}
|
|
};
|
|
}
|
|
|
|
public function test_all_taobao_family_platforms_trigger_the_matching_receipt_sources(): void
|
|
{
|
|
$reflection = new ReflectionClass(AccountMappingResyncDispatcher::class);
|
|
$map = $reflection->getConstant('PLATFORM_MAP');
|
|
|
|
$this->assertSame(
|
|
[['taobao-alipay', '淘系支付宝'], ['taobao-wechat', '淘系微信']],
|
|
$map['淘宝']
|
|
);
|
|
$this->assertSame(
|
|
[['taobao-alipay', '淘系支付宝'], ['taobao-wechat', '淘系微信']],
|
|
$map['天猫']
|
|
);
|
|
$this->assertSame([['taobao-alipay', '淘系支付宝']], $map['阿里巴巴']);
|
|
}
|
|
|
|
public function test_platform_without_receipt_sync_is_a_noop(): void
|
|
{
|
|
$result = app(AccountMappingResyncDispatcher::class)->dispatchFor(['唯品会JX']);
|
|
|
|
$this->assertSame(['jobs' => 0], $result);
|
|
}
|
|
}
|