Files
portal/app/tests/Unit/External/SupplierBalanceProviderTest.php
T
Дмитрий 22ad20337a feat(балансы): баланс поставщика = остаток номеров × 20 ₽
У кабинета crm.bp-gr нет денежного баланса — есть «Баланс ГЦК» (остаток номеров)
в выпадашке шапки (table.balancetbl). supplier-balance.js логинится, раскрывает
выпадашку, читает «Баланс ГЦК» -> {numbers}. Провайдер: деньги = numbers ×
number_price_rub (20 ₽/шт, подтверждено владельцем). Live: 3096 -> 61 920 ₽.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 07:54:10 +03:00

57 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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');
});
it('переводит остаток номеров в деньги (номера × цена)', function () {
config()->set('services.supplier.number_price_rub', 20);
$bridge = Mockery::mock(PlaywrightBridge::class);
$bridge->shouldReceive('run')->once()->andReturn(['numbers' => 3096]);
app()->instance(PlaywrightBridge::class, $bridge);
$r = app(SupplierBalanceProvider::class)->fetch();
expect($r->ok)->toBeTrue();
expect($r->balance)->toBe(61920.0); // 3096 × 20 ₽
expect($r->serviceKey)->toBe('supplier');
});
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();
});
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();
});