Files
HeuJung 56a78e1d55 feat(api-docs): 요청/응답 예시 블록 + 8종 결함 근본 수정 + audit error 승격
API 레퍼런스에 요청 예시(raw HTTP)·응답 예시(envelope 전문)를 표준 포맷에
편입하고, 전 대상(코어+전 모듈+전 플러그인)에 방출했다. 예시 결함 8종
(multipart·Host 마스킹·write 실측·path 치환·현실적 바디·query 반영·중복
제거·민감값 마스킹)을 스캐폴더/프로브 공용 수정으로 근본 해소했다.

추가로 검증에서 드러난 결함을 마감했다:
- 응답 예시 body 의 절대 URL(페이지네이터·콜백) 호스트를 placeholder 로
 마스킹(maskResponseHost) — 요청 Host 헤더만 마스킹되던 누락 보완, 확장
 39건 정정
- api:docgen 커맨드 통합 테스트 신설(라우트 수집·확장 라우팅·rules 추출·
 멱등 재생성·check drift)
- module-routing.md URL 스킴 오류 정정(/api/admin → /api/modules)
- README·cheatsheet·api-documentation 에 API 문서 커맨드/레퍼런스 진입점 반영

전 대상 3칸 완료로 api-doc-coverage 룰을 warn→error 승격.
2026-07-08 18:22:34 +09:00

84 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Plugins\Sirsoft\Gdpr\Tests\Unit\Support;
use App\Contracts\ApiDoc\ApiDocSampleSeeder;
use App\Models\User;
use Plugins\Sirsoft\Gdpr\Models\GdprPolicyVersion;
use Plugins\Sirsoft\Gdpr\Support\ApiDoc\ApiDocSampleService;
use Plugins\Sirsoft\Gdpr\Tests\PluginTestCase;
/**
* sirsoft-gdpr API 문서 실측용 완전 샘플 시더 테스트.
*
* 정책 버전 상세 GET(`admin/policy-versions/{version}`) 실측을 위한 발행 정책 버전
* 대표 샘플이 생성되고, `policy-versions` 도메인의 path_params 맵이 반환되며,
* 재실행 시 멱등한지 검증한다.
*/
class ApiDocSampleServiceTest extends PluginTestCase
{
/**
* 실제 docgen 실행에서는 코어 ApiDocSampleService 가 먼저 실측 사용자를 시드한다.
* 정책 버전의 created_by 소유자를 만족시키기 위해 사용자를 먼저 만든다.
*/
protected function setUp(): void
{
parent::setUp();
User::factory()->create([
'email' => 'apidoc-sample-user@example.com',
'name' => 'API 문서 샘플 사용자',
]);
}
/**
* 시더가 계약을 구현한다.
*/
public function test_seeder_implements_contract(): void
{
$this->assertInstanceOf(ApiDocSampleSeeder::class, new ApiDocSampleService);
}
/**
* 시더가 발행된 정책 버전 대표 샘플을 생성한다.
*/
public function test_seed_creates_policy_version(): void
{
(new ApiDocSampleService)->seed();
$version = GdprPolicyVersion::query()->where('version', 1)->first();
$this->assertNotNull($version);
$this->assertSame(1, $version->version);
$this->assertNotNull($version->change_type);
}
/**
* 시더가 policy-versions 도메인의 path_params 맵을 반환한다.
*/
public function test_seed_returns_policy_versions_path_params_map(): void
{
$map = (new ApiDocSampleService)->seed();
$this->assertArrayHasKey('policy-versions', $map);
$entry = $map['policy-versions'];
$this->assertSame(GdprPolicyVersion::class, $entry['model']);
$this->assertSame('version', $entry['key']);
$this->assertArrayHasKey('version', $entry['path_params']);
$this->assertSame('1', $entry['path_params']['version']);
}
/**
* 재실행 시 정책 버전이 중복 생성되지 않는다 (멱등).
*/
public function test_seed_is_idempotent(): void
{
(new ApiDocSampleService)->seed();
(new ApiDocSampleService)->seed();
$this->assertSame(1, GdprPolicyVersion::query()->where('version', 1)->count());
}
}