- 알림톡 발송이 카카오 승인 템플릿의 본문·버튼·요소를 실제로 채워 보내도록 구현(B안): 카카오 상세조회 + template_code 단위 캐시(기본 60분, 수동 초기화·끄기 지원), 카카오→발송 형식 변환 + 변수 치환 - 결과코드 재시도 분류 정정(알림톡 일시오류 7306/7307/7421/7437 추가) - 발신프로필 응답 파싱 정정(data.success[]) - 연결한 카카오 템플릿 소실(삭제·차단·미승인) 시 알림 설정에 "사용 불가" 표시, 조회 실패/승인 없음 구분 안내(결함 2·3)
97 lines
3.6 KiB
PHP
97 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Plugins\Sirsoft\MessageBizppurio\Tests\Unit\Services;
|
|
|
|
use Illuminate\Support\Facades\App;
|
|
use Plugins\Sirsoft\MessageBizppurio\Enums\ResultCategory;
|
|
use Plugins\Sirsoft\MessageBizppurio\Services\ResultCodeResolver;
|
|
use Plugins\Sirsoft\MessageBizppurio\Tests\PluginTestCase;
|
|
|
|
/**
|
|
* ResultCodeResolver — 결과코드 분류·사유·라벨 검증 (계획서 D11).
|
|
*/
|
|
class ResultCodeResolverTest extends PluginTestCase
|
|
{
|
|
private ResultCodeResolver $resolver;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
App::setLocale('ko');
|
|
$this->resolver = new ResultCodeResolver;
|
|
}
|
|
|
|
/**
|
|
* 성공 코드(발송 1000 / SMS 4100 / LMS 6600 / 알림톡 7000 / 카카오 200)는 Success.
|
|
*/
|
|
public function test_success_codes_categorized_as_success(): void
|
|
{
|
|
foreach (['1000', '4100', '6600', '7000', '200'] as $code) {
|
|
$this->assertSame(ResultCategory::Success, $this->resolver->categorize($code), "코드 {$code}");
|
|
$this->assertTrue($this->resolver->isSuccess($code), "코드 {$code}");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 잔액부족(9070 문자 / 7436 알림톡)은 BalanceLow + isBalanceLow true.
|
|
*/
|
|
public function test_balance_low_codes(): void
|
|
{
|
|
foreach (['9070', '7436'] as $code) {
|
|
$this->assertSame(ResultCategory::BalanceLow, $this->resolver->categorize($code), "코드 {$code}");
|
|
$this->assertTrue($this->resolver->isBalanceLow($code), "코드 {$code}");
|
|
$this->assertFalse($this->resolver->isSuccess($code), "코드 {$code}");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 일시오류 코드는 Retry.
|
|
*
|
|
* 공통(5003/5004/5005/9000/3011/3013)에 더해, 알림톡 일시오류(7306 카카오 시스템오류·
|
|
* 7307 처리지연·7421 타임아웃·7437 메시지 요청실패)도 재시도 대상이다. 7305(성공 불확실)는
|
|
* 이미 발송됐을 수 있어 중복발송 위험이 있으므로 재시도 대상에서 제외한다.
|
|
*/
|
|
public function test_retryable_codes_categorized_as_retry(): void
|
|
{
|
|
foreach (['5003', '5004', '5005', '9000', '3011', '3013', '7306', '7307', '7421', '7437'] as $code) {
|
|
$this->assertSame(ResultCategory::Retry, $this->resolver->categorize($code), "코드 {$code}");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 7305(성공 불확실)는 중복발송 위험으로 재시도 대상이 아니다(영구실패로 분류).
|
|
*/
|
|
public function test_success_uncertain_7305_is_not_retryable(): void
|
|
{
|
|
$this->assertNotSame(ResultCategory::Retry, $this->resolver->categorize('7305'));
|
|
}
|
|
|
|
/**
|
|
* 위 분류에 없는 코드는 영구 실패.
|
|
*/
|
|
public function test_unknown_and_failure_codes_are_permanent_failure(): void
|
|
{
|
|
foreach (['4400', '6606', '7204', '2000', '9999'] as $code) {
|
|
$this->assertSame(ResultCategory::PermanentFailure, $this->resolver->categorize($code), "코드 {$code}");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* reason 은 lang 정의 코드는 사유를, 미정의 코드는 null 을 반환.
|
|
*/
|
|
public function test_reason_resolves_defined_codes_and_null_for_unknown(): void
|
|
{
|
|
$this->assertSame('음영 지역', $this->resolver->reason('4400'));
|
|
$this->assertNull($this->resolver->reason('9999'));
|
|
}
|
|
|
|
/**
|
|
* label 은 정의 코드는 "사유 (코드)", 미정의 코드는 코드만 반환.
|
|
*/
|
|
public function test_label_formats_reason_with_code(): void
|
|
{
|
|
$this->assertSame('음영 지역 (4400)', $this->resolver->label('4400'));
|
|
$this->assertSame('9999', $this->resolver->label('9999'));
|
|
}
|
|
}
|