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건만 잔존.
178 lines
6.3 KiB
PHP
178 lines
6.3 KiB
PHP
<?php
|
|
|
|
namespace Plugins\Sirsoft\MessageBizppurio\Tests\Unit\Services;
|
|
|
|
use App\Services\PluginSettingsService;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Mockery;
|
|
use Plugins\Sirsoft\MessageBizppurio\Exceptions\BizppurioApiException;
|
|
use Plugins\Sirsoft\MessageBizppurio\Services\BizppurioApiClient;
|
|
use Plugins\Sirsoft\MessageBizppurio\Services\BizppurioTokenService;
|
|
use Plugins\Sirsoft\MessageBizppurio\Tests\PluginTestCase;
|
|
|
|
/**
|
|
* BizppurioApiClient — /v3/message 발송·결과코드·토큰 재발급 재시도 검증.
|
|
*/
|
|
class BizppurioApiClientTest extends PluginTestCase
|
|
{
|
|
private const IDENTIFIER = 'sirsoft-message_bizppurio';
|
|
|
|
private array $payload = [
|
|
'account' => 'acct',
|
|
'type' => 'sms',
|
|
'from' => '07012345678',
|
|
'to' => '01011112222',
|
|
'refkey' => 'ref1',
|
|
'content' => ['sms' => ['message' => 'hi']],
|
|
];
|
|
|
|
private function makeSettings(bool $isTestMode = true): PluginSettingsService
|
|
{
|
|
$mock = Mockery::mock(PluginSettingsService::class);
|
|
$mock->shouldReceive('get')
|
|
->with(self::IDENTIFIER, 'is_test_mode', true)
|
|
->andReturn($isTestMode);
|
|
|
|
return $mock;
|
|
}
|
|
|
|
/**
|
|
* getToken/refreshToken 을 순차 반환하는 TokenService mock.
|
|
*
|
|
* @param string $token getToken 반환 토큰
|
|
* @param string|null $refreshed refreshToken 반환 토큰(null 이면 미기대)
|
|
*/
|
|
private function makeToken(string $token, ?string $refreshed = null): BizppurioTokenService
|
|
{
|
|
$mock = Mockery::mock(BizppurioTokenService::class);
|
|
$mock->shouldReceive('getToken')->andReturn($token);
|
|
|
|
if ($refreshed !== null) {
|
|
$mock->shouldReceive('refreshToken')->once()->andReturn($refreshed);
|
|
}
|
|
|
|
return $mock;
|
|
}
|
|
|
|
public function test_발송_성공(): void
|
|
{
|
|
Http::fake([
|
|
'*/v3/message' => Http::response([
|
|
'code' => 1000, 'description' => 'Success', 'refkey' => 'ref1', 'messagekey' => 'mk1',
|
|
], 200),
|
|
]);
|
|
|
|
$client = new BizppurioApiClient($this->makeToken('TOKEN'), $this->makeSettings());
|
|
$result = $client->sendMessage($this->payload);
|
|
|
|
$this->assertTrue($client->isSuccess($result));
|
|
$this->assertSame('mk1', $result['messagekey']);
|
|
Http::assertSent(fn ($request) => $request->hasHeader('Authorization', 'Bearer TOKEN'));
|
|
}
|
|
|
|
public function test_토큰무효_3002는_재발급_후_1회_재시도(): void
|
|
{
|
|
Http::fake([
|
|
'*/v3/message' => Http::sequence()
|
|
->push(['code' => 3002, 'description' => 'Invalid token'], 200)
|
|
->push(['code' => 1000, 'description' => 'Success', 'messagekey' => 'mk2'], 200),
|
|
]);
|
|
|
|
$client = new BizppurioApiClient(
|
|
$this->makeToken('OLD', 'NEW'),
|
|
$this->makeSettings(),
|
|
);
|
|
$result = $client->sendMessage($this->payload);
|
|
|
|
$this->assertTrue($client->isSuccess($result));
|
|
Http::assertSentCount(2);
|
|
}
|
|
|
|
public function test_운영_모드는_live_도메인_호출(): void
|
|
{
|
|
Http::fake([
|
|
'api.bizppurio.com/*' => Http::response(['code' => 1000], 200),
|
|
]);
|
|
|
|
$client = new BizppurioApiClient($this->makeToken('T'), $this->makeSettings(false));
|
|
$client->sendMessage($this->payload);
|
|
|
|
Http::assertSent(fn ($request) => str_starts_with($request->url(), 'https://api.bizppurio.com'));
|
|
}
|
|
|
|
public function test_http_실패시_예외(): void
|
|
{
|
|
Http::fake(['*/v3/message' => Http::response([], 500)]);
|
|
|
|
$client = new BizppurioApiClient($this->makeToken('T'), $this->makeSettings());
|
|
|
|
$this->expectException(BizppurioApiException::class);
|
|
$client->sendMessage($this->payload);
|
|
}
|
|
|
|
/**
|
|
* HTTP 실패 응답에 code·description 이 있으면 예외에 사유·결과코드로 담긴다.
|
|
*
|
|
* 회귀 배경: 실패 시 "메시지 발송 요청에 실패했습니다"만 뜨고 비즈뿌리오가 준 실제 사유·코드를
|
|
* 버려, 발송 이력·로그로 원인을 알 수 없던 문제. 실패 body 를 추출해 예외에 실어 이력에 남긴다.
|
|
*/
|
|
public function test_http_실패시_응답_body_의_사유와_코드가_예외에_담긴다(): void
|
|
{
|
|
Http::fake([
|
|
'*/v3/message' => Http::response(
|
|
['code' => 7103, 'description' => '발신 프로필 키가 유효하지 않음'],
|
|
400,
|
|
),
|
|
]);
|
|
|
|
$client = new BizppurioApiClient($this->makeToken('T'), $this->makeSettings());
|
|
|
|
try {
|
|
$client->sendMessage($this->payload);
|
|
$this->fail('예외가 발생해야 한다.');
|
|
} catch (BizppurioApiException $e) {
|
|
$this->assertSame('7103', $e->getResultCode(), '실패 body 의 code 가 예외에 담겨야 한다.');
|
|
$this->assertSame('발신 프로필 키가 유효하지 않음', $e->getMessage(), '실패 body 의 description 이 예외 메시지로 담겨야 한다.');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* HTTP 실패 응답에 body 가 없으면 기본 사유로 폴백하고 결과코드는 null.
|
|
*/
|
|
public function test_http_실패시_body_없으면_기본_사유_폴백(): void
|
|
{
|
|
Http::fake(['*/v3/message' => Http::response([], 500)]);
|
|
|
|
$client = new BizppurioApiClient($this->makeToken('T'), $this->makeSettings());
|
|
|
|
try {
|
|
$client->sendMessage($this->payload);
|
|
$this->fail('예외가 발생해야 한다.');
|
|
} catch (BizppurioApiException $e) {
|
|
$this->assertNull($e->getResultCode());
|
|
$this->assertNotSame('', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function test_영구실패_결과코드는_그대로_반환(): void
|
|
{
|
|
Http::fake([
|
|
'*/v3/message' => Http::response(['code' => 3006, 'description' => 'Account error'], 200),
|
|
]);
|
|
|
|
$client = new BizppurioApiClient($this->makeToken('T'), $this->makeSettings());
|
|
$result = $client->sendMessage($this->payload);
|
|
|
|
$this->assertFalse($client->isSuccess($result));
|
|
$this->assertSame(3006, $result['code']);
|
|
// 3006 은 재시도 대상 아님 → HTTP 1회
|
|
Http::assertSentCount(1);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
parent::tearDown();
|
|
}
|
|
}
|