Add has_landing plus landing_* deploy keys, deduct balance on withdraw request, keep app_url for SMS login links, and clarify Zarin rial wallet document titles. Co-authored-by: Cursor <cursoragent@cursor.com>
109 lines
3.4 KiB
PHP
109 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Services\ConfigService;
|
|
use Illuminate\Http\Request;
|
|
use Mockery;
|
|
use Tests\TestCase;
|
|
|
|
class ConfigServiceOtpHostTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
parent::tearDown();
|
|
}
|
|
|
|
/** @param mixed $appUrl */
|
|
private function cfgWithAppUrl($appUrl): ConfigService
|
|
{
|
|
$cfg = Mockery::mock(ConfigService::class)->makePartial();
|
|
$cfg->shouldReceive('get')->andReturnUsing(function (string $key, $default = null) use ($appUrl) {
|
|
if ($key === 'app_url') {
|
|
return $appUrl !== null && $appUrl !== '' ? $appUrl : $default;
|
|
}
|
|
|
|
return $default;
|
|
});
|
|
|
|
return $cfg;
|
|
}
|
|
|
|
public function test_uses_request_host_without_settings(): void
|
|
{
|
|
$request = Request::create('https://boursemes.com/server/auth/login', 'POST');
|
|
$this->app->instance('request', $request);
|
|
|
|
$host = $this->cfgWithAppUrl(null)->resolvePublicHost($request);
|
|
|
|
$this->assertSame('boursemes.com', $host);
|
|
}
|
|
|
|
public function test_resolve_public_site_url_from_request(): void
|
|
{
|
|
$request = Request::create('https://boursemes.com/server/auth/login', 'POST');
|
|
|
|
$url = $this->cfgWithAppUrl(null)->resolvePublicSiteUrl($request);
|
|
|
|
$this->assertSame('https://boursemes.com', $url);
|
|
}
|
|
|
|
public function test_prefers_app_url_over_api_request_host(): void
|
|
{
|
|
$request = Request::create('https://goldarvin.gholaktala.ir/server/customer/order', 'POST');
|
|
$this->app->instance('request', $request);
|
|
|
|
$cfg = $this->cfgWithAppUrl('https://my.goldarvin.ir');
|
|
|
|
$this->assertSame('my.goldarvin.ir', $cfg->resolvePublicHost($request));
|
|
$this->assertSame('https://my.goldarvin.ir', $cfg->resolvePublicSiteUrl($request));
|
|
}
|
|
|
|
public function test_does_not_fall_back_to_laravel_api_host(): void
|
|
{
|
|
config(['app.url' => 'https://goldarvin.gholaktala.ir/server']);
|
|
$request = Request::create('https://goldarvin.gholaktala.ir/server/admin/customer', 'POST');
|
|
$this->app->instance('request', $request);
|
|
|
|
$this->assertSame('', $this->cfgWithAppUrl(null)->resolvePublicSiteUrl($request));
|
|
$this->assertSame('', $this->cfgWithAppUrl(null)->resolvePublicHost($request));
|
|
}
|
|
|
|
public function test_app_url_without_scheme_gets_https(): void
|
|
{
|
|
$request = Request::create('https://goldarvin.gholaktala.ir/server/auth/login', 'POST');
|
|
|
|
$this->assertSame(
|
|
'https://my.goldarvin.ir',
|
|
$this->cfgWithAppUrl('my.goldarvin.ir')->resolvePublicSiteUrl($request)
|
|
);
|
|
}
|
|
|
|
public function test_returns_empty_without_request(): void
|
|
{
|
|
$host = $this->cfgWithAppUrl(null)->resolvePublicHost();
|
|
|
|
$this->assertSame('', $host);
|
|
}
|
|
|
|
public function test_strips_www_prefix(): void
|
|
{
|
|
$request = Request::create('https://www.boursemes.com/server/auth/login', 'POST');
|
|
|
|
$host = $this->cfgWithAppUrl(null)->resolvePublicHost($request);
|
|
|
|
$this->assertSame('boursemes.com', $host);
|
|
}
|
|
|
|
public function test_skips_localhost_request_host(): void
|
|
{
|
|
$request = Request::create('http://localhost/server/auth/login', 'POST');
|
|
$this->app->instance('request', $request);
|
|
|
|
$host = $this->cfgWithAppUrl(null)->resolvePublicHost($request);
|
|
|
|
$this->assertSame('', $host);
|
|
}
|
|
}
|