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건만 잔존.
188 lines
7.2 KiB
PHP
188 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace Plugins\Sirsoft\MessageBizppurio\Tests\Unit\Jobs;
|
|
|
|
use Illuminate\Http\Client\ConnectionException;
|
|
use Mockery;
|
|
use Plugins\Sirsoft\MessageBizppurio\Enums\DispatchStatus;
|
|
use Plugins\Sirsoft\MessageBizppurio\Exceptions\BizppurioApiException;
|
|
use Plugins\Sirsoft\MessageBizppurio\Jobs\SendMessageJob;
|
|
use Plugins\Sirsoft\MessageBizppurio\Models\BizppurioDispatch;
|
|
use Plugins\Sirsoft\MessageBizppurio\Repositories\Contracts\BizppurioDispatchRepositoryInterface;
|
|
use Plugins\Sirsoft\MessageBizppurio\Services\BizppurioApiClient;
|
|
use Plugins\Sirsoft\MessageBizppurio\Tests\PluginTestCase;
|
|
|
|
/**
|
|
* SendMessageJob — 성공/일시오류 재시도/영구실패 판정 + 이력 갱신 검증(Phase 4).
|
|
*/
|
|
class SendMessageJobTest extends PluginTestCase
|
|
{
|
|
private array $payload = [
|
|
'account' => 'acct', 'type' => 'sms', 'from' => '070', 'to' => '010',
|
|
'refkey' => 'ref1', 'content' => ['sms' => ['message' => 'hi']],
|
|
];
|
|
|
|
/**
|
|
* sendMessage 응답을 반환하는 ApiClient mock 을 만듭니다.
|
|
*
|
|
* @param array<string, mixed> $result sendMessage 반환값
|
|
*/
|
|
private function makeClient(array $result): BizppurioApiClient
|
|
{
|
|
$mock = Mockery::mock(BizppurioApiClient::class);
|
|
$mock->shouldReceive('sendMessage')->with($this->payload)->andReturn($result);
|
|
$mock->shouldReceive('isSuccess')
|
|
->andReturnUsing(fn ($r) => (string) ($r['code'] ?? '') === '1000');
|
|
|
|
return $mock;
|
|
}
|
|
|
|
/**
|
|
* 컨테이너에서 실제 리포지토리(Provider 바인딩)를 해석해 반환.
|
|
*/
|
|
private function dispatches(): BizppurioDispatchRepositoryInterface
|
|
{
|
|
return app(BizppurioDispatchRepositoryInterface::class);
|
|
}
|
|
|
|
/**
|
|
* refkey 로 pending 이력을 1건 seed.
|
|
*/
|
|
private function seedPending(string $refkey): BizppurioDispatch
|
|
{
|
|
return BizppurioDispatch::create([
|
|
'refkey' => $refkey,
|
|
'channel' => 'sms',
|
|
'to_number' => '01011112222',
|
|
'content' => 'hi',
|
|
'status' => DispatchStatus::Pending->value,
|
|
'source' => 'auto',
|
|
]);
|
|
}
|
|
|
|
public function test_성공시_예외없이_종료하고_이력을_sent로_갱신한다(): void
|
|
{
|
|
$dispatch = $this->seedPending('ref1');
|
|
|
|
$job = new SendMessageJob($this->payload, 'ref1');
|
|
$job->handle($this->makeClient(['code' => 1000, 'messagekey' => 'mk']), $this->dispatches());
|
|
|
|
$dispatch->refresh();
|
|
$this->assertSame(DispatchStatus::Sent, $dispatch->status);
|
|
$this->assertSame('mk', $dispatch->messagekey);
|
|
}
|
|
|
|
public function test_일시오류_결과코드는_예외를_던져_재시도한다(): void
|
|
{
|
|
$job = new SendMessageJob($this->payload, 'ref1');
|
|
|
|
$this->expectException(BizppurioApiException::class);
|
|
|
|
try {
|
|
$job->handle($this->makeClient(['code' => 5003, 'description' => 'temp']), $this->dispatches());
|
|
} catch (BizppurioApiException $e) {
|
|
$this->assertSame('5003', $e->getResultCode());
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
public function test_알림톡_일시오류_결과코드는_예외를_던져_재시도한다(): void
|
|
{
|
|
// 알림톡 일시오류(7306 카카오 시스템오류·7307 처리지연·7421 타임아웃·7437 요청실패)는
|
|
// 다시 보내면 성공할 수 있으므로 예외를 던져 큐가 재시도해야 한다.
|
|
foreach (['7306', '7307', '7421', '7437'] as $code) {
|
|
$job = new SendMessageJob($this->payload, 'ref1');
|
|
|
|
try {
|
|
$job->handle($this->makeClient(['code' => (int) $code, 'description' => 'temp']), $this->dispatches());
|
|
$this->fail("코드 {$code} 는 재시도(예외)여야 한다");
|
|
} catch (BizppurioApiException $e) {
|
|
$this->assertSame($code, $e->getResultCode(), "코드 {$code}");
|
|
}
|
|
}
|
|
}
|
|
|
|
public function test_영구실패_결과코드는_예외없이_종료하고_이력을_failed로_갱신한다(): void
|
|
{
|
|
$dispatch = $this->seedPending('ref1');
|
|
|
|
// 3006(계정오류) = 영구실패 → 재시도 안 함(예외 없음)
|
|
$job = new SendMessageJob($this->payload, 'ref1');
|
|
$job->handle($this->makeClient(['code' => 3006, 'description' => 'account error']), $this->dispatches());
|
|
|
|
$dispatch->refresh();
|
|
$this->assertSame(DispatchStatus::Failed, $dispatch->status);
|
|
$this->assertSame('3006', $dispatch->result_code);
|
|
}
|
|
|
|
public function test_tries와_backoff_기본값(): void
|
|
{
|
|
$job = new SendMessageJob($this->payload, 'ref1');
|
|
|
|
$this->assertSame(2, $job->tries);
|
|
$this->assertSame(2, $job->backoff());
|
|
}
|
|
|
|
public function test_after_commit_활성화(): void
|
|
{
|
|
$job = new SendMessageJob($this->payload, 'ref1');
|
|
|
|
$this->assertTrue($job->afterCommit);
|
|
}
|
|
|
|
public function test_최종실패_콜백은_pending이력을_failed로_마감하고_사유를_기록한다(): void
|
|
{
|
|
// 타임아웃·연결실패는 결과코드 없는 ConnectionException 으로 재시도 소진 후 failed() 로 온다.
|
|
$dispatch = $this->seedPending('ref1');
|
|
|
|
$job = new SendMessageJob($this->payload, 'ref1');
|
|
$job->failed(new ConnectionException('cURL error 28: Connection timed out'));
|
|
|
|
$dispatch->refresh();
|
|
$this->assertSame(DispatchStatus::Failed, $dispatch->status);
|
|
$this->assertNull($dispatch->result_code); // 전송 실패라 결과코드 없음
|
|
$this->assertStringContainsString('timed out', (string) $dispatch->result_message);
|
|
}
|
|
|
|
public function test_최종실패_콜백은_bizppurio_api_exception의_결과코드를_보존한다(): void
|
|
{
|
|
$dispatch = $this->seedPending('ref1');
|
|
|
|
$job = new SendMessageJob($this->payload, 'ref1');
|
|
$job->failed(new BizppurioApiException('일시 오류', resultCode: '5003'));
|
|
|
|
$dispatch->refresh();
|
|
$this->assertSame(DispatchStatus::Failed, $dispatch->status);
|
|
$this->assertSame('5003', $dispatch->result_code);
|
|
}
|
|
|
|
public function test_이미_확정된_이력은_최종실패_콜백이_덮어쓰지_않는다(): void
|
|
{
|
|
// webhook 이 먼저 success 로 확정한 뒤 failed() 가 늦게 불려도 멱등해야 한다.
|
|
$dispatch = $this->seedPending('ref1');
|
|
$dispatch->update(['status' => DispatchStatus::Success->value, 'result_code' => '4000']);
|
|
|
|
$job = new SendMessageJob($this->payload, 'ref1');
|
|
$job->failed(new ConnectionException('timed out'));
|
|
|
|
$dispatch->refresh();
|
|
$this->assertSame(DispatchStatus::Success, $dispatch->status);
|
|
$this->assertSame('4000', $dispatch->result_code);
|
|
}
|
|
|
|
public function test_이력이_없으면_최종실패_콜백은_아무것도_하지_않는다(): void
|
|
{
|
|
// 이력 seed 없이 호출 — 예외 없이 조용히 종료해야 한다.
|
|
$job = new SendMessageJob($this->payload, 'missing-ref');
|
|
$job->failed(new ConnectionException('timed out'));
|
|
|
|
$this->assertDatabaseMissing('bizppurio_dispatches', ['refkey' => 'missing-ref']);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
parent::tearDown();
|
|
}
|
|
}
|