Files
Gnuboard7/plugins/_bundled/sirsoft-message_bizppurio/tests/Unit/Models/BizppurioDispatchTest.php
T
chym1217 77df8c9a7c feat(message_bizppurio): 발송 결과 기록 + webhook 수신 + 결과코드
문자·알림톡 발송 결과를 DB에 기록하고, 비즈뿌리오 webhook(URL PUSH)으로
도달 여부를 갱신한다. 결과코드를 사유+분류로 해석하고, 잔액 부족 시
관리자에게 쿨다운(기본 1시간) 내 1회만 알린다.

발송 결과를 확인하는 화면은 플러그인 독립 페이지 대신 코어 알림 이력에
얹는 방식(후속)으로 이관하기로 하여, 이번에 만든 독립 이력 화면과
화면 전용 백엔드는 제거했다. webhook 결과 저장·수신·해석 뼈대는 유지한다.
2026-07-28 12:36:21 +09:00

91 lines
2.6 KiB
PHP

<?php
namespace Plugins\Sirsoft\MessageBizppurio\Tests\Unit\Models;
use App\Models\User;
use Plugins\Sirsoft\MessageBizppurio\Enums\DispatchChannel;
use Plugins\Sirsoft\MessageBizppurio\Enums\DispatchStatus;
use Plugins\Sirsoft\MessageBizppurio\Models\BizppurioDispatch;
use Plugins\Sirsoft\MessageBizppurio\Tests\PluginTestCase;
/**
* BizppurioDispatch 모델 — 캐스트·마스킹 접근자·회원 관계 검증.
*/
class BizppurioDispatchTest extends PluginTestCase
{
/**
* enum 캐스트가 적용된다.
*/
public function test_enum_casts(): void
{
$dispatch = BizppurioDispatch::create([
'refkey' => 'r1',
'channel' => 'lms',
'to_number' => '01011112222',
'content' => 'x',
'status' => 'pending',
'source' => 'auto',
]);
$this->assertSame(DispatchChannel::Lms, $dispatch->channel);
$this->assertSame(DispatchStatus::Pending, $dispatch->status);
}
/**
* 마스킹 접근자는 가운데 4자리를 가린다.
*/
public function test_masked_number(): void
{
$dispatch = new BizppurioDispatch(['to_number' => '01012345678']);
$this->assertSame('010-****-5678', $dispatch->masked_number);
}
/**
* 하이픈 포함 번호도 정규화 후 마스킹한다.
*/
public function test_masked_number_with_hyphens(): void
{
$dispatch = new BizppurioDispatch(['to_number' => '010-1234-5678']);
$this->assertSame('010-****-5678', $dispatch->masked_number);
}
/**
* to_user_id 로 회원 관계를 로드한다.
*/
public function test_user_relation(): void
{
$user = User::factory()->create();
$dispatch = BizppurioDispatch::create([
'refkey' => 'r2',
'channel' => 'sms',
'to_number' => '01011112222',
'to_user_id' => $user->id,
'content' => 'x',
'status' => 'sent',
'source' => 'auto',
]);
$this->assertNotNull($dispatch->user);
$this->assertSame($user->id, $dispatch->user->id);
}
/**
* byRefkey 스코프로 조회한다.
*/
public function test_by_refkey_scope(): void
{
BizppurioDispatch::create([
'refkey' => 'unique_ref',
'channel' => 'sms',
'to_number' => '01000000000',
'content' => 'x',
'status' => 'sent',
'source' => 'auto',
]);
$found = BizppurioDispatch::query()->byRefkey('unique_ref')->first();
$this->assertNotNull($found);
$this->assertSame('unique_ref', $found->refkey);
}
}