Files
portal/app/tests/Feature/ClientTg/RobotResultTest.php
T

52 lines
1.5 KiB
PHP
Raw Normal View History

<?php
use App\Services\ClientTg\RobotResult;
it('пробрасывает строковый actualCostRub из JSON робота', function () {
$r = RobotResult::fromRobotJson([
'ok' => true,
'matched' => 437,
'actualCostRub' => '201.60',
]);
expect($r->actualCostRub)->toBe('201.60');
expect($r->ok)->toBeTrue();
});
it('приводит числовой actualCostRub к строке', function () {
$r = RobotResult::fromRobotJson([
'ok' => true,
'actualCostRub' => 201.6,
]);
expect($r->actualCostRub)->toBe('201.6');
expect($r->actualCostRub)->not->toBeNull();
});
it('без поля actualCostRub оставляет null и не ломает остальные поля', function () {
$r = RobotResult::fromRobotJson([
'ok' => true,
'matched' => 12,
'campaignId' => '555',
]);
expect($r->actualCostRub)->toBeNull();
expect($r->ok)->toBeTrue();
expect($r->matched)->toBe(12);
expect($r->campaignId)->toBe('555');
});
it('failed() не выставляет actualCostRub', function () {
$r = RobotResult::failed('таймаут');
expect($r->actualCostRub)->toBeNull();
expect($r->ok)->toBeFalse();
expect($r->reason)->toBe('таймаут');
});
it('конструктор без actualCostRub даёт null по умолчанию', function () {
$r = new RobotResult(ok: true);
expect($r->actualCostRub)->toBeNull();
});