53 lines
1.9 KiB
PHP
53 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
uses(DatabaseTransactions::class);
|
|
|
|
beforeEach(function () {
|
|
DB::table('external_service_balances')->delete();
|
|
});
|
|
|
|
it('GET /api/admin/dashboard/balances показывает proxy_market со сроком «до …» и остатком дней', function () {
|
|
config()->set('services.proxy_market.expires_at', now()->addDays(18)->format('Y-m-d'));
|
|
config()->set('services.proxy_market.topup_url', 'https://proxy.market/');
|
|
|
|
DB::table('external_service_balances')->insert([
|
|
'service_key' => 'proxy_market', 'currency' => 'RUB',
|
|
'light' => 'green', 'ok' => true,
|
|
'checked_at' => now(), 'created_at' => now(), 'updated_at' => now(),
|
|
]);
|
|
|
|
$resp = $this->getJson('/api/admin/dashboard/balances');
|
|
$resp->assertOk();
|
|
|
|
$row = collect($resp->json('services'))->firstWhere('service_key', 'proxy_market');
|
|
expect($row)->not->toBeNull();
|
|
expect($row['expires_at'])->toBe(now()->addDays(18)->format('d.m.Y'));
|
|
expect($row['days_left'])->toBe(18);
|
|
expect($row['topup_url'])->toBe('https://proxy.market/');
|
|
});
|
|
|
|
it('битая дата в сроке не роняет дашборд (expires_at null, 200)', function () {
|
|
config()->set('services.proxy_market.expires_at', 'не-дата');
|
|
|
|
DB::table('external_service_balances')->insert([
|
|
'service_key' => 'proxy_market',
|
|
'currency' => 'RUB',
|
|
'light' => 'green',
|
|
'ok' => true,
|
|
'checked_at' => now(),
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$resp = $this->getJson('/api/admin/dashboard/balances');
|
|
$resp->assertOk();
|
|
$row = collect($resp->json('services'))->firstWhere('service_key', 'proxy_market');
|
|
expect($row)->not->toBeNull();
|
|
expect($row['expires_at'])->toBeNull();
|
|
});
|