refactor(ProductRepo): 优化 getRate 方法参数处理

- 将 getRate 方法的 $uid 参数变更为可选参数
- 使用 array_filter 过滤空值,避免在请求中发送不必要的参数
- 增加了两个单元测试用例,分别测试不带 uid 和带 uid 的情况
This commit is contained in:
李东云
2025-09-19 16:39:09 +08:00
parent e7e1c7f6c9
commit c552dd8ed0
2 changed files with 15 additions and 3 deletions

View File

@@ -206,11 +206,11 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
* @return float
* @throws GuzzleException
*/
public function getRate(PointType $source, PointType $target, string $uid): float
public function getRate(PointType $source, PointType $target, ?string $uid = null): float
{
$response = $this->requestService->requestGet(
url: "/rpc/v2/products/$target->value/exchange-rate/$source->value",
params: ['uid' => $uid]
params: array_filter(['uid' => $uid]),
);
$content = $response->getBody()->getContents();

View File

@@ -23,4 +23,16 @@ it('can query point rate', function () {
$rate = $repo->getRate($from, $to, $uid);
expect($rate)->toBeFloat();
});
})->only();
it('can query point rate with uid', function () {
$repo = make(ProductRepo::class);
$from = PointType::FtaiAligner;
$to = PointType::LuxPoint;
$uid = 'cn3321';
$rate = $repo->getRate($from, $to, $uid);
expect($rate)->toBeFloat();
})->only();