fix(settings): honor last-price switch and overlay only SuperAdmin access flags

Stored DB prices were treated as live quotes, and SuperAdmin overlay overwrote tenant keys like trading hours. Keep overlay to the 14 access flags and hide fallback prices when the panel says so.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-25 03:01:07 +03:30
co-authored by Cursor
parent 8984899042
commit b21b136711
9 changed files with 327 additions and 97 deletions
@@ -3,6 +3,7 @@
namespace Tests\Unit;
use App\Services\ConfigService;
use App\Services\SuperAdminProgramSettingsOverlay;
use Carbon\Carbon;
use Mockery;
use Tests\TestCase;
@@ -119,6 +120,9 @@ class ConfigServiceTradingHoursTest extends TestCase
$this->assertTrue($result['closed']);
$this->assertSame('closed', $result['status']);
$this->assertSame(0, $result['buy']);
$this->assertSame(0, $result['sell']);
$this->assertSame(0, $result['price']);
Carbon::setTestNow();
}
@@ -189,14 +193,87 @@ class ConfigServiceTradingHoursTest extends TestCase
'sell' => 100,
'buy' => 110,
'price' => 105,
'price_source' => 'montzar',
'montzar' => 105,
]);
$this->assertFalse($result['closed']);
$this->assertSame('open', $result['status']);
$this->assertSame(110, $result['buy']);
Carbon::setTestNow();
}
/**
* سناریوی گزارش‌شده: مظنه زنده قطع است و قیمت از آخرین ردیف prices آمده،
* ولی «نمایش آخرین قیمت ذخیره‌شده» خاموش است → نباید قیمت نشان داده شود.
*/
public function test_stored_price_is_hidden_when_show_last_price_is_off(): void
{
$cfg = $this->cfg([
'close_price' => 'false',
'show_last_price' => 'false',
'show_home_price_when_closed' => 'false',
]);
$result = $cfg->applyHomePriceDisplayState([
'sell' => 168336410,
'buy' => 168798112,
'price' => 168798112,
'price_last' => 168798112,
'price_source' => 'database_last',
'montzar' => 0,
'zaarbox' => 0,
'main_product' => 0,
]);
$this->assertFalse($result['closed']);
$this->assertSame('no_quote', $result['status']);
$this->assertSame(0, $result['buy']);
$this->assertSame(0, $result['sell']);
$this->assertSame(0, $result['price']);
$this->assertSame(0, $result['price_last']);
}
public function test_live_quote_detection_ignores_database_fallback(): void
{
$cfg = $this->cfg([]);
$this->assertTrue($cfg->payloadHasLiveQuote([
'buy' => 110,
'price_source' => 'montzar',
]));
$this->assertFalse($cfg->payloadHasLiveQuote([
'buy' => 110,
'price_source' => 'database_last',
]));
// منابع زندهٔ دیگر مثل tala_ir نباید «ذخیره‌شده» حساب شوند
$this->assertTrue($cfg->payloadHasLiveQuote([
'buy' => 110,
'price_source' => 'tala_ir',
]));
// بدون برچسب منبع، عددِ مرجع زنده تصمیم می‌گیرد
$this->assertTrue($cfg->payloadHasLiveQuote([
'buy' => 110,
'zaarbox' => 105,
]));
$this->assertFalse($cfg->payloadHasLiveQuote([
'buy' => 110,
'montzar' => 0,
'zaarbox' => 0,
'main_product' => 0,
]));
$this->assertFalse($cfg->payloadHasLiveQuote([
'buy' => 0,
'price_source' => 'montzar',
]));
}
public function test_trading_hours_setting_keys(): void
{
$cfg = new ConfigService();
@@ -206,4 +283,19 @@ class ConfigServiceTradingHoursTest extends TestCase
$this->assertTrue($cfg->isTradingHoursSettingKey('show_home_price_when_closed'));
$this->assertFalse($cfg->isTradingHoursSettingKey('name_fa'));
}
/** کلیدهای ساعت کاری باید مالکیت tenant داشته باشند وگرنه پنل اثری روی قیمت ندارد */
public function test_trading_hours_keys_are_tenant_owned(): void
{
foreach (ConfigService::TRADING_HOURS_CLIENT_KEYS as $key) {
$this->assertTrue(
SuperAdminProgramSettingsOverlay::isLocalOwned($key),
"{$key} باید local-owned باشد"
);
$this->assertFalse(
SuperAdminProgramSettingsOverlay::isSuperAdminOwned($key),
"{$key} نباید سوپرادمین-اونر باشد"
);
}
}
}