79 lines
3.2 KiB
PHP
79 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Illuminate\Http\Client\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Modules\EcommerceFinance\Services\JushuitanPlatformBalanceClient;
|
|
use Tests\TestCase;
|
|
|
|
class JushuitanPlatformBalanceClientTest extends TestCase
|
|
{
|
|
public function test_it_reads_and_parses_a_platform_balance_month(): void
|
|
{
|
|
config([
|
|
'services.jushuitan.erp_account' => 'test-account',
|
|
'services.jushuitan.erp_password' => 'test-password',
|
|
'services.jushuitan.erp_login_url' => 'https://erp.test/Login/Passport',
|
|
'services.jushuitan.pdd_balance_url' => 'https://erp.test/balance?pk=PinDuoDuoPlatform&gk=PinduoduoImport',
|
|
'services.jushuitan.timeout' => 5,
|
|
]);
|
|
|
|
$rows = [[
|
|
'platFormName' => '拼多多',
|
|
'groupName' => '拼多多货款账户',
|
|
'shopId' => 22203955,
|
|
'shopName' => '拼多多-测试店',
|
|
'openingBalance' => 0,
|
|
'currentIncome' => 100.25,
|
|
'currentExpenditure' => 20.10,
|
|
'endingBalance' => 80.15,
|
|
'endingBalanceRpa' => 80.15,
|
|
'haveOpeningBalance' => true,
|
|
'haveEndingBalanceRpa' => true,
|
|
]];
|
|
$loadResponse = '0|' . json_encode([
|
|
'IsSuccess' => true,
|
|
'ReturnValue' => [
|
|
'paging' => ['PageCount' => 1],
|
|
'datalist' => json_encode($rows, JSON_UNESCAPED_UNICODE),
|
|
],
|
|
], JSON_UNESCAPED_UNICODE);
|
|
|
|
Http::fake(function (Request $request) use ($loadResponse) {
|
|
if ($request->url() === 'https://erp.test/Login/Passport') {
|
|
$this->assertSame('test-account', $request['data']['account']);
|
|
$this->assertSame('test-password', $request['data']['password']);
|
|
|
|
return Http::response(['code' => 0, 'data' => ['msg' => 'ok']]);
|
|
}
|
|
if ($request->method() === 'GET') {
|
|
return Http::response(<<<'HTML'
|
|
<html><head><title>平台资金账户余额</title></head><body>
|
|
<input id="__VIEWSTATE" value="view-state" />
|
|
<input id="__VIEWSTATEGENERATOR" value="generator" />
|
|
</body></html>
|
|
HTML);
|
|
}
|
|
|
|
$this->assertStringContainsString('am___=LoadData', $request->url());
|
|
$this->assertSame('view-state', $request['__VIEWSTATE']);
|
|
$this->assertSame('generator', $request['__VIEWSTATEGENERATOR']);
|
|
$this->assertSame('ACall1', $request['__CALLBACKID']);
|
|
$callback = json_decode($request['__CALLBACKPARAM'], true, 512, JSON_THROW_ON_ERROR);
|
|
$conditions = json_decode($callback['Args'][0], true, 512, JSON_THROW_ON_ERROR);
|
|
$this->assertSame('2026-11-01', $conditions['begin_time']);
|
|
$this->assertSame('2026-11-30', $conditions['end_time']);
|
|
|
|
return Http::response($loadResponse);
|
|
});
|
|
|
|
$result = app(JushuitanPlatformBalanceClient::class)->fetchMonth('2026-11');
|
|
|
|
$this->assertCount(1, $result);
|
|
$this->assertSame('拼多多-测试店', $result[0]['shopName']);
|
|
$this->assertSame(0, $result[0]['openingBalance']);
|
|
$this->assertSame(80.15, $result[0]['endingBalanceRpa']);
|
|
}
|
|
}
|