mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 03:55:07 +08:00
refactor(ProductRepo): 优化 getRate 方法参数处理
- 将 getRate 方法的 $uid 参数变更为可选参数 - 使用 array_filter 过滤空值,避免在请求中发送不必要的参数 - 增加了两个单元测试用例,分别测试不带 uid 和带 uid 的情况
This commit is contained in:
@@ -206,11 +206,11 @@ final class ProductRepo extends AbstractRepo implements RechargeProductRepoInter
|
|||||||
* @return float
|
* @return float
|
||||||
* @throws GuzzleException
|
* @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(
|
$response = $this->requestService->requestGet(
|
||||||
url: "/rpc/v2/products/$target->value/exchange-rate/$source->value",
|
url: "/rpc/v2/products/$target->value/exchange-rate/$source->value",
|
||||||
params: ['uid' => $uid]
|
params: array_filter(['uid' => $uid]),
|
||||||
);
|
);
|
||||||
|
|
||||||
$content = $response->getBody()->getContents();
|
$content = $response->getBody()->getContents();
|
||||||
|
|||||||
@@ -23,4 +23,16 @@ it('can query point rate', function () {
|
|||||||
|
|
||||||
$rate = $repo->getRate($from, $to, $uid);
|
$rate = $repo->getRate($from, $to, $uid);
|
||||||
expect($rate)->toBeFloat();
|
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();
|
||||||
|
|||||||
Reference in New Issue
Block a user