2026-06-28 07:11:02 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
use App\Services\External\SupplierBalanceProvider;
|
|
|
|
|
|
use App\Services\Supplier\PlaywrightBridge;
|
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
|
|
|
|
uses(TestCase::class); // нужен booted-app: config()/app()
|
|
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
|
config()->set('services.supplier.login', 'u');
|
|
|
|
|
|
config()->set('services.supplier.password', 'p');
|
|
|
|
|
|
config()->set('services.supplier.portal_url', 'https://crm.bp-gr.ru');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-06-28 07:54:10 +03:00
|
|
|
|
it('переводит остаток номеров в деньги (номера × цена)', function () {
|
|
|
|
|
|
config()->set('services.supplier.number_price_rub', 20);
|
2026-06-28 07:11:02 +03:00
|
|
|
|
$bridge = Mockery::mock(PlaywrightBridge::class);
|
2026-06-28 07:54:10 +03:00
|
|
|
|
$bridge->shouldReceive('run')->once()->andReturn(['numbers' => 3096]);
|
2026-06-28 07:11:02 +03:00
|
|
|
|
app()->instance(PlaywrightBridge::class, $bridge);
|
|
|
|
|
|
|
|
|
|
|
|
$r = app(SupplierBalanceProvider::class)->fetch();
|
|
|
|
|
|
expect($r->ok)->toBeTrue();
|
2026-06-28 07:54:10 +03:00
|
|
|
|
expect($r->balance)->toBe(61920.0); // 3096 × 20 ₽
|
2026-06-28 07:11:02 +03:00
|
|
|
|
expect($r->serviceKey)->toBe('supplier');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-06-28 07:54:10 +03:00
|
|
|
|
it('нет числа номеров в ответе → fail', function () {
|
|
|
|
|
|
$bridge = Mockery::mock(PlaywrightBridge::class);
|
|
|
|
|
|
$bridge->shouldReceive('run')->once()->andReturn(['oops' => true]);
|
|
|
|
|
|
app()->instance(PlaywrightBridge::class, $bridge);
|
|
|
|
|
|
|
|
|
|
|
|
$r = app(SupplierBalanceProvider::class)->fetch();
|
|
|
|
|
|
expect($r->ok)->toBeFalse();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-06-28 07:11:02 +03:00
|
|
|
|
it('мост бросил → fail, не пробрасывает исключение', function () {
|
|
|
|
|
|
$bridge = Mockery::mock(PlaywrightBridge::class);
|
|
|
|
|
|
$bridge->shouldReceive('run')->andThrow(new RuntimeException('exit 2: balance not found'));
|
|
|
|
|
|
app()->instance(PlaywrightBridge::class, $bridge);
|
|
|
|
|
|
|
|
|
|
|
|
$r = app(SupplierBalanceProvider::class)->fetch();
|
|
|
|
|
|
expect($r->ok)->toBeFalse();
|
|
|
|
|
|
expect($r->error)->toContain('exit 2');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('нет логина → fail без запуска моста', function () {
|
|
|
|
|
|
config()->set('services.supplier.login', '');
|
|
|
|
|
|
$bridge = Mockery::mock(PlaywrightBridge::class);
|
|
|
|
|
|
$bridge->shouldNotReceive('run');
|
|
|
|
|
|
app()->instance(PlaywrightBridge::class, $bridge);
|
|
|
|
|
|
|
|
|
|
|
|
$r = app(SupplierBalanceProvider::class)->fetch();
|
|
|
|
|
|
expect($r->ok)->toBeFalse();
|
|
|
|
|
|
});
|