발송 결과(성공/실패·사유·잔액부족·SMS 대체발송)를 코어 "알림 발송 이력" 화면의 각 행에 표시한다. 코어 앱·코어 테이블 무수정 — 연결 표식은 bizppurio_dispatches.notification_log_id 에만 두고, 발송 사이클의 코어 after_log_sent/after_log_failed 훅으로 그 로그 id 를 연결한다. - 결과 조회는 파라미터 없는 GET /dispatch-results/recent 로 최근 결과 맵을 받아 row.id 매칭 (목록 로드 순서에 무관 — 빈 배열 전송·타이밍으로 결과가 비던 문제 해소). - 코어 이력 datagrid 에 결과 컬럼을 layout_extensions 로 주입하고, 행 토글에도 상세 결과를 얹는다. 메일·사이트내알림 탭에선 컬럼(헤더 포함)을 숨긴다. 다크모드 배지 색 보강. - 브라우저 검수용 데모 시더(4상태·엣지 케이스 21건) + 전 계층 테스트(백엔드·Vitest 렌더) + 시나리오 매니페스트 + API 레퍼런스 동반.
114 lines
4.1 KiB
PHP
114 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Plugins\Sirsoft\MessageBizppurio\Tests\Unit\Services;
|
|
|
|
use Plugins\Sirsoft\MessageBizppurio\Models\BizppurioDispatch;
|
|
use Plugins\Sirsoft\MessageBizppurio\Repositories\BizppurioDispatchRepository;
|
|
use Plugins\Sirsoft\MessageBizppurio\Services\DispatchResultService;
|
|
use Plugins\Sirsoft\MessageBizppurio\Services\ResultCodeResolver;
|
|
use Plugins\Sirsoft\MessageBizppurio\Tests\PluginTestCase;
|
|
|
|
/**
|
|
* DispatchResultService — 코어 로그 id 배열 → 결과 표시 맵 변환 검증 (A-2 표시 주입).
|
|
*
|
|
* ResultCodeResolver 재사용으로 상태·`사유 (코드)`·잔액부족·대체발송을 파생하고, 매칭되지 않는
|
|
* 로그 id 는 맵에서 빠지는지(빈 셀) 확인한다. 전화번호 등 민감정보는 결과에 포함하지 않는다.
|
|
*/
|
|
class DispatchResultServiceTest extends PluginTestCase
|
|
{
|
|
private DispatchResultService $service;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->service = new DispatchResultService(
|
|
new BizppurioDispatchRepository,
|
|
new ResultCodeResolver,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 코어 로그 id 에 연결된 dispatch 1건을 만듭니다.
|
|
*
|
|
* @param array<string, mixed> $overrides dispatch 오버라이드
|
|
*/
|
|
private function linkedDispatch(int $logId, array $overrides = []): BizppurioDispatch
|
|
{
|
|
return BizppurioDispatch::create(array_merge([
|
|
'refkey' => 'r'.uniqid(),
|
|
'channel' => 'sms',
|
|
'to_number' => '01011112222',
|
|
'content' => 'x',
|
|
'notification_type' => 'welcome',
|
|
'notification_log_id' => $logId,
|
|
'status' => 'success',
|
|
'result_code' => '4100',
|
|
'source' => 'auto',
|
|
'sent_at' => now(),
|
|
], $overrides));
|
|
}
|
|
|
|
public function test_성공_결과를_로그id_키_맵으로_반환한다(): void
|
|
{
|
|
$this->linkedDispatch(10);
|
|
|
|
$results = $this->service->resultsForLogIds([10]);
|
|
|
|
$this->assertArrayHasKey(10, $results);
|
|
$this->assertSame('success', $results[10]['status']);
|
|
$this->assertSame('4100', $results[10]['result_code']);
|
|
$this->assertFalse($results[10]['is_low_balance']);
|
|
// 민감정보(전화번호)는 결과에 포함하지 않는다.
|
|
$this->assertArrayNotHasKey('to_number', $results[10]);
|
|
}
|
|
|
|
public function test_잔액부족_코드는_is_low_balance_true다(): void
|
|
{
|
|
$this->linkedDispatch(20, ['channel' => 'alimtalk', 'status' => 'failed', 'result_code' => '7436']);
|
|
|
|
$results = $this->service->resultsForLogIds([20]);
|
|
|
|
$this->assertTrue($results[20]['is_low_balance']);
|
|
}
|
|
|
|
public function test_대체발송_상태가_결과에_포함된다(): void
|
|
{
|
|
$this->linkedDispatch(30, ['fallback_status' => '성공']);
|
|
|
|
$results = $this->service->resultsForLogIds([30]);
|
|
|
|
$this->assertSame('성공', $results[30]['fallback_status']);
|
|
}
|
|
|
|
public function test_result_code_없으면_result_label_null이다(): void
|
|
{
|
|
$this->linkedDispatch(40, ['status' => 'sent', 'result_code' => null]);
|
|
|
|
$results = $this->service->resultsForLogIds([40]);
|
|
|
|
$this->assertNull($results[40]['result_label']);
|
|
$this->assertNotNull($results[40]['status_label']); // 상태 라벨은 있음(발송중)
|
|
}
|
|
|
|
public function test_매칭되지_않는_로그id는_맵에서_빠진다(): void
|
|
{
|
|
$this->linkedDispatch(50);
|
|
|
|
$results = $this->service->resultsForLogIds([50, 999]);
|
|
|
|
$this->assertArrayHasKey(50, $results);
|
|
$this->assertArrayNotHasKey(999, $results);
|
|
}
|
|
|
|
public function test_recent_results_는_연결된_최근_결과를_로그id_키_맵으로_반환한다(): void
|
|
{
|
|
$this->linkedDispatch(60, ['result_code' => '4100']);
|
|
$this->linkedDispatch(61, ['channel' => 'alimtalk', 'status' => 'failed', 'result_code' => '7436']);
|
|
|
|
$results = $this->service->recentResults();
|
|
|
|
$this->assertSame('success', $results[60]['status']);
|
|
$this->assertTrue($results[61]['is_low_balance']);
|
|
}
|
|
}
|