Files
portal/app/tests/Unit/Supplier/SupplierOrderVerifierTest.php
T

64 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
use App\Services\Supplier\SupplierOrderVerifier;
it('нет расхождений когда живое совпадает с задуманным', function (): void {
$intended = [
['signal_type' => 'call', 'identifier' => '79135397707', 'platform' => 'B1', 'limit' => 1],
];
$shouldBeOff = [];
$live = [
['signal_type' => 'call', 'identifier' => '79135397707', 'platform' => 'B1', 'limit' => 1, 'on' => true],
];
expect(SupplierOrderVerifier::diff($intended, $shouldBeOff, $live))->toBe([]);
});
it('ловит limit_drift', function (): void {
$intended = [['signal_type' => 'site', 'identifier' => 'inssmart.ru', 'platform' => 'B2', 'limit' => 2]];
$live = [['signal_type' => 'site', 'identifier' => 'inssmart.ru', 'platform' => 'B2', 'limit' => 5, 'on' => true]];
$m = SupplierOrderVerifier::diff($intended, [], $live);
expect($m)->toHaveCount(1)
->and($m[0]['kind'])->toBe('limit_drift')
->and($m[0]['expected'])->toBe(2)
->and($m[0]['actual'])->toBe(5);
});
it('ловит should_be_off (пауза не дошла = деньги)', function (): void {
$shouldBeOff = [['signal_type' => 'site', 'identifier' => 'automoney.ru', 'platform' => 'B3']];
$live = [['signal_type' => 'site', 'identifier' => 'automoney.ru', 'platform' => 'B3', 'limit' => 1, 'on' => true]];
$m = SupplierOrderVerifier::diff([], $shouldBeOff, $live);
expect($m)->toHaveCount(1)->and($m[0]['kind'])->toBe('should_be_off');
});
it('ловит should_be_on', function (): void {
$intended = [['signal_type' => 'call', 'identifier' => '7911', 'platform' => 'B1', 'limit' => 1]];
$live = [['signal_type' => 'call', 'identifier' => '7911', 'platform' => 'B1', 'limit' => 1, 'on' => false]];
$m = SupplierOrderVerifier::diff($intended, [], $live);
expect($m)->toHaveCount(1)->and($m[0]['kind'])->toBe('should_be_on');
});
it('ловит missing (задумали, у поставщика нет)', function (): void {
$intended = [['signal_type' => 'call', 'identifier' => '7911', 'platform' => 'B2', 'limit' => 1]];
$m = SupplierOrderVerifier::diff($intended, [], []);
expect($m)->toHaveCount(1)->and($m[0]['kind'])->toBe('missing');
});
it('ловит orphan_extra (у поставщика лишняя наша строка)', function (): void {
$live = [['signal_type' => 'site', 'identifier' => 'ghost.ru', 'platform' => 'B1', 'limit' => 3, 'on' => true]];
$m = SupplierOrderVerifier::diff([], [], $live);
expect($m)->toHaveCount(1)->and($m[0]['kind'])->toBe('orphan_extra');
});