CaiWuXiTong/tests/Unit/EcommerceFinance/ProductCostAutoRefreshTest.php

51 lines
1.6 KiB
PHP

<?php
namespace Tests\Unit\EcommerceFinance;
use InvalidArgumentException;
use Modules\EcommerceFinance\Services\ProductCostAutoRefresh;
use Tests\TestCase;
class ProductCostAutoRefreshTest extends TestCase
{
public function test_it_runs_product_cost_for_the_updated_month_and_platform(): void
{
$calls = [];
$service = new ProductCostAutoRefresh(
static function (array $command) use (&$calls): array {
$calls[] = $command;
return ['success' => true, 'output' => 'ok'];
},
);
$result = $service->refresh('2026-10', 'taobao-alipay');
$this->assertSame('succeeded', $result['status']);
$this->assertSame(['taobao-alipay'], $result['platforms']);
$this->assertCount(1, $calls);
$this->assertContains('store-receipt:product-cost:sync', $calls[0]);
$this->assertContains('2026-10', $calls[0]);
$this->assertContains('--platform=taobao-alipay', $calls[0]);
}
public function test_it_reports_a_failed_product_cost_refresh(): void
{
$service = new ProductCostAutoRefresh(
static fn (array $command): array => ['success' => false, 'output' => 'failed'],
);
$result = $service->refresh('2026-10', 'pinduoduo');
$this->assertSame('failed', $result['status']);
$this->assertFalse($result['results'][0]['success']);
}
public function test_it_rejects_an_invalid_month(): void
{
$this->expectException(InvalidArgumentException::class);
(new ProductCostAutoRefresh())->refresh('2026-10-01', 'taobao-alipay');
}
}