Files
Gnuboard7/plugins/_bundled/sirsoft-message_bizppurio/tests/Unit/Services/DispatchResultServiceTest.php
T
HeuJung 6a8a537f10 feat(message_bizppurio): 임시 삭제된 비즈뿌리오 플러그인 복구 및 현행 규정 정합화
32afe9530 에서 게시판 반응 기능과 함께 임시 제거됐던 비즈뿌리오 메시징
플러그인 본체(137 파일)와 일본어 번들 언어팩(9 파일)을 삭제 직전 상태
(32afe9530~1)로 복구한다. 템플릿 신청·승인 개편의 기반 작업.

복구 범위
- plugins/_bundled/sirsoft-message_bizppurio 전체 + 번들 ja 언어팩
- 공유 파일의 비즈뿌리오 참조 복원: build-language-pack-ja.cjs 팩 정의,
 api-doc-unfilled-baseline.json(32건), docs/backend/api/README.md 표 행,
 audit coverage 노트·vite-sourcemap-env-gate 룰 주석, via 테스트 주석,
 ·AGENTS.md 확장 API 표(자동 재생성), 라우팅 패리티 스냅샷(+1)

삭제 이후 강화된 규정 2건 정합화
- TokenCheckController: 예외 원문을 메시지 키 자리에 전달하던 422 응답을
 키(token_check.failed) + errors.bizppurio_message 페이로드로 분리
 (GenericCatchStatusCodeContractTest 계약). 관리자 토스트는 errors 페이로드로
 상세 사유를 계속 표시하도록 레이아웃 동기 수정, lang ko/en/ja 키 추가
- AlimtalkTemplateController::index: base Request 주입 금지 룰에 따라
 AlimtalkTemplateListRequest FormRequest 신설 (형태 검증만 — kapi 위임 유지)

미복원(의도)
- 게시판·이커머스 CHANGELOG 의 알림톡 연결 문구 2줄은 연결 방식이 로
 재설계되므로 되살리지 않고, 완료 시점에 새 동작 기준으로 차기 버전에 기재

검증: TokenCheck 7 + AlimtalkController 10 + GenericCatch 계약 3 (PHPUnit),
플러그인 레이아웃 Vitest 137건, BindingShape 라우팅 패리티 8건 green.
audit 는 복구 전부터 baseline 처리된 API 문서 미채움 32건만 잔존.
2026-08-22 22:39:36 +09:00

146 lines
5.4 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_검수_모드_스냅샷이_결과에_포함된다(): void
{
$this->linkedDispatch(70, ['is_test_mode' => true]);
$results = $this->service->resultsForLogIds([70]);
$this->assertTrue($results[70]['is_test_mode']);
}
public function test_검수_모드_스냅샷이_없는_과거_이력은_null이다(): void
{
$this->linkedDispatch(71, ['is_test_mode' => null]);
$results = $this->service->resultsForLogIds([71]);
$this->assertNull($results[71]['is_test_mode']);
}
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']);
}
/**
* 실제 발송 본문(dispatch.content)이 결과에 포함된다 — 알림톡은 코어
* notification_logs.body(대체발송용 코어 템플릿 값)와 실제 카카오 발송 내용이 달라,
* 화면이 채널별로 구분해 실제 발송 내용을 보여줄 수 있도록 결과에 담아야 한다.
*/
public function test_실제_발송_본문이_결과에_포함된다(): void
{
$this->linkedDispatch(80, ['content' => '[그누보드7] 회원가입을 환영합니다\n\n김으네님, 가입이 완료되었습니다.']);
$results = $this->service->resultsForLogIds([80]);
$this->assertSame('[그누보드7] 회원가입을 환영합니다\n\n김으네님, 가입이 완료되었습니다.', $results[80]['content']);
}
}