- Postman 공식 사이트에서 다운로드
- 무료 계정으로도 충분히 사용 가능
- Postman 실행
Import버튼 클릭postman_collection.json파일 선택Import클릭
Import버튼 클릭postman_environment.json파일 선택- 우측 상단에서 환경을
SecondChap Development로 선택
baseUrl:http://localhost:3000(개발 서버 주소)accessToken: Spotify 액세스 토큰 (자동 설정됨)sessionToken: NextAuth 세션 토큰 (수동 설정 필요)testAlbumId: 테스트용 앨범 IDtestArtistId: 테스트용 아티스트 IDtestQuery: 테스트용 검색 쿼리testCountry: 테스트용 국가 코드
GET {{baseUrl}}/api/spotify/token
- 목적: Spotify API 액세스 토큰 획득
- 응답:
access_token,token_type,expires_in - 자동화: 토큰이 환경 변수에 자동 저장됨
GET {{baseUrl}}/api/spotify/search-or-new-releases?q={{testQuery}}&country={{testCountry}}
- 파라미터:
q: 검색 쿼리 (예: "BTS", "Ed Sheeran")country: 국가 코드 (KR, US, JP, GB)genre: 장르 필터 (k-pop, pop, rock 등)favoriteArtistIds: 즐겨찾기 아티스트 ID들
- 브라우저에서
http://localhost:3000접속 - 개발자 도구 → Application → Cookies
next-auth.session-token값 복사- Postman 환경 변수
sessionToken에 설정
GET {{baseUrl}}/api/favorites
Headers: Cookie: next-auth.session-token={{sessionToken}}
POST {{baseUrl}}/api/favorites
Headers:
- Content-Type: application/json
- Cookie: next-auth.session-token={{sessionToken}}
Body:
{
"type": "album",
"spotifyId": "{{testAlbumId}}",
"name": "Test Album",
"image": "https://example.com/image.jpg"
}
- 상태 코드: 200 (성공), 401 (인증 필요), 404 (찾을 수 없음), 500 (서버 오류)
- 응답 시간: API 성능 확인
- 응답 크기: 데이터 양 확인
// Postman Tests 탭에서 사용할 수 있는 스크립트
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response has required fields", function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("albums");
pm.expect(jsonData).to.have.property("artists");
});
pm.test("Response time is less than 2000ms", function () {
pm.expect(pm.response.responseTime).to.be.below(2000);
});// Spotify 토큰 자동 저장
if (pm.response.code === 200) {
const response = pm.response.json();
pm.collectionVariables.set("accessToken", response.access_token);
console.log("Spotify token saved:", response.access_token);
}// Pre-request Script 탭에서 사용
// 현재 시간을 타임스탬프로 설정
pm.environment.set("timestamp", new Date().getTime());
// 랜덤 테스트 데이터 생성
pm.environment.set("randomId", Math.random().toString(36).substr(2, 9));- 컬렉션 우클릭 →
Run collection - 테스트할 요청들 선택
Run SecondChap API Collection클릭- 결과 확인
# Newman 설치
npm install -g newman
# 컬렉션 실행
newman run postman_collection.json -e postman_environment.json
# HTML 리포트 생성
newman run postman_collection.json -e postman_environment.json -r html --reporter-html-export report.html# GitHub Actions 예시
- name: Run API Tests
run: |
newman run postman_collection.json -e postman_environment.json- Spotify 토큰 획득
- 아티스트 검색
- 앨범 검색
- 국가별 필터링
- 장르별 필터링
- 로그인 없이 즐겨찾기 접근 (401 에러 확인)
- 유효한 세션으로 즐겨찾기 접근
- 즐겨찾기 추가/삭제
- 잘못된 엔드포인트 (404 에러)
- 잘못된 Spotify ID (400 에러)
- 서버 오류 시뮬레이션
- 응답 시간 측정
- 대용량 데이터 처리
- 동시 요청 처리
- 컬렉션 우클릭 →
Mock collection - Mock URL 생성
- 예상 응답 설정
- 개발 중 API 의존성 제거
- 컬렉션 →
View Documentation - 자동 생성된 문서 확인
- 팀과 공유
Monitor탭에서 새 모니터 생성- 정기적인 API 상태 확인
- 알림 설정
- 개발 서버 실행: 테스트 전에
npm run dev로 서버 실행 - 환경 변수:
.env.local파일의 Spotify API 키 확인 - 세션 토큰: 로그인 후에만 즐겨찾기 API 테스트 가능
- Rate Limiting: Spotify API 호출 제한 주의
- 데이터 정합성: 테스트 데이터와 실제 데이터 구분
- 401 Unauthorized: 세션 토큰 확인
- 500 Internal Server Error: 서버 로그 확인
- 빈 응답: Spotify API 키 확인
- 느린 응답: 네트워크 상태 확인
# 개발 서버 로그 확인
npm run dev
# 또는 터미널에서 직접 확인
tail -f .next/server.log이 가이드를 따라하면 Postman을 사용해서 SecondChap 프로젝트의 모든 API를 체계적으로 테스트하고 디버깅할 수 있습니다!