feat(смс): канал СМС-центр (smsc.ru) — универсал

This commit is contained in:
Дмитрий
2026-07-23 11:59:37 +03:00
parent a13691a230
commit bbea378bf1
2 changed files with 140 additions and 0 deletions
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
use App\Services\Sms\Providers\SmscSmsProvider;
use App\Services\Sms\SmsOutgoing;
use App\Services\Sms\SmsSendException;
use Illuminate\Support\Facades\Http;
function smsc_provider(): SmscSmsProvider
{
return new SmscSmsProvider('login', 'secret', ['*'], ['*' => 300]);
}
function smsc_message(): SmsOutgoing
{
return new SmsOutgoing(
phone: '79990000001',
body: 'Здравствуйте!',
senderName: 'liderra.ru',
operator: 'МегаФон',
segments: 1,
);
}
it('обслуживает всех как универсал', function () {
expect(smsc_provider()->servesOperators())->toBe(['*'])
->and(smsc_provider()->key())->toBe('smsc');
});
it('успешная отправка возвращает id сообщения и цену по сегментам', function () {
Http::fake(['smsc.ru/*' => Http::response(['id' => 555, 'cnt' => 1], 200)]);
$result = smsc_provider()->send(smsc_message());
expect($result->providerMessageId)->toBe('555')
->and($result->costKopecks)->toBe(300);
});
it('отказ smsc.ru бросает terminal-исключение', function () {
Http::fake(['smsc.ru/*' => Http::response(['error' => 'invalid number', 'error_code' => 7], 200)]);
expect(fn () => smsc_provider()->send(smsc_message()))
->toThrow(SmsSendException::class);
});
it('сетевой сбой — не terminal (можно повторить)', function () {
Http::fake(['smsc.ru/*' => Http::response('', 500)]);
try {
smsc_provider()->send(smsc_message());
$this->fail('ожидалось SmsSendException');
} catch (SmsSendException $e) {
expect($e->terminal)->toBeFalse();
}
});