통합 테스트 - LeeEuyJoon/lilling-be GitHub Wiki

1. 목적

API 전체 플로우 (URL 단축 → DB 저장 → 리다이렉트)를 실제 환경에서 검증한다.

2. 테스트 환경

구성 요소 세부 내용
Testcontainers MySQL 8.0, Redis 7-alpine
MockMvc Spring MVC 요청/응답 검증
KgsClient Mock 처리 (외부 KGS 의존 제거)

3. 테스트 시나리오

1️⃣ URL 단축 전체 플로우

POST /api/v1/url/shorten

  • 응답 코드: HTTP 200 OK
  • 응답 JSON 내 shortUrl 존재
  • DB 저장 필드 검증
    (id, kgsId, scrambledId, shortUrl, appId, createdAt)

2️⃣ 여러 URL 단축

  • 서로 다른 3개의 URL 입력
  • 각 URL의 kgsId, scrambledId모두 고유해야 함

3️⃣ ShortCode 길이 검증

  • shortCode.length ≤ 7
  • Base62 문자셋만 포함 (0–9, a–z, A–Z)

4️⃣ 리다이렉트 전체 플로우

GET /{shortCode}

  • 응답 코드: HTTP 301 Moved Permanently
  • Location 헤더 값이 원본 URL과 일치해야 함

4. 검증 흐름 요약

POST /api/v1/url/shorten
 → Controller → Service → Repository → MySQL
 → Base62Encoder + IdScrambler 검증

GET /{shortCode}
 → Base62 decode → unscramble → findOriginalUrl
 → HTTP 301 Redirect