Test: Challenge 리펙토링 및 테스트 작성 (#191)#201
Merged
HyejeongSon merged 11 commits intodevelopfrom Jun 28, 2025
Merged
Conversation
VarGun
approved these changes
Jun 28, 2025
Contributor
|
테스트 describe 왜 죄다 영어로 해놓으셨는지...ㅋㅋㅋㅋ |
KimGiii
approved these changes
Jun 28, 2025
Contributor
Author
ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 연관된 이슈 번호
🌱 주요 변경 사항
1. 비즈니스 로직 분리
app/api/challenge/claim/route.ts: 인증/권한 검증 및 API 응답 처리app/actions/get-challenge.ts: 서버 액션으로 챌린지 목록 조회services/challenge/challenge-claim.ts: 순수 비즈니스 로직 (보상 지급 처리)services/challenge/challenge-status.ts: 챌린지 상태 계산 공통 로직2. 공통 로직 추출
3. 테스트 작성
디렉토리 구조
테스트 실행
Challenge Status Service테스트 (challenge-status.test.ts)calculateChallengeStatus 테스트
CLAIMEDuserChallengeClaims에 항목이 있는 경우 무조건CLAIMED상태를 반환해야 함ACHIEVABLEprogressVal이 1 이상이면 수령 가능한 상태INCOMPLETEACHIEVABLEupdatedAt이 오늘이라면 수령 가능INCOMPLETEACHIEVABLEprogressVal이 있고updatedAt이 오늘이면 수령 가능ACHIEVABLEupdatedAt은 없어도createdAt이 오늘이고 진행도가 있다면 수령 가능CLAIMEDuserChallengeClaims에 오늘 날짜가 있는 경우CLAIMED반환INCOMPLETEprogressVal이 0이라면 미완료 상태INCOMPLETEuserChallengeProgresses배열이 비어 있는 경우 도전 자체를 안 한 상태로 간주canClaimChallenge 테스트
false, 이유: "Challenge not found"challenge.findUnique결과가null인 경우false, 이유: "Already claimed"userChallengeClaims에 해당 챌린지가 존재하면 수령 불가truecalculateChallengeStatus결과가ACHIEVABLE이면 수령 가능false, 이유: "Challenge not completed"Challenge Claim Service테스트 (challenge-claim.test.ts)userChallengeClaim.create호출 확인userChallengeProgress.updateMany호출되지 않아야 함eTFTransaction.create가 올바르게 호출되고transactionId확인userChallengeClaim.create호출 확인userChallengeProgress.updateMany가progressVal: 0으로 호출되었는지 확인eTFTransaction.create호출 및transactionId반환 검증challenge.findUnique가null인 경우 챌린지를 찾을 수 없어야 합니다.success: false와"Challenge not found"메시지를 반환해야 함"ISA account not found"메시지가 반환되어야 함etfDailyTrading.findFirst결과가null인 경우 최신 종가가 없다고 판단해야 합니다."Latest ETF price not found"메시지를 반환해야 하며 이후 로직은 실행되지 않아야 함(10×1500 + 5×2000)/15 = 1666.67로 정확히 수행되어야 함eTFHolding.upsert호출 시 해당 값이 정확히 반영되어야 함quantity와price가 소수점을 포함하더라도 평균단가 계산이 정확해야 합니다.(3.5×1400.25 + 2.5×1500.75)/6.0 = 1442.125계산 정확도 검증eTFHolding.upsert에 정확히 전달되어야 함challenge claim API테스트 (challenge-claim-api.test.ts)getServerSession결과가null인 경우 인증되지 않은 사용자로 간주401 Unauthorized상태 코드와"Unauthorized"메시지를 반환해야 함challengeId가 누락된 경우400 Bad Request상태 코드와"Challenge ID is required"메시지를 반환해야 함challengeId로 요청한 경우canClaimChallenge가true,claimChallengeReward가success: true일 때200 OK상태 코드와"Reward claimed successfully"메시지,transactionId가 반환되어야 함canClaimChallenge가false이며reason이 존재하는 경우throw된 에러 메시지가"Already claimed"인지 확인500 Internal Server Error로 반환되어야 함canClaimChallenge는 통과했지만claimChallengeReward가success: false를 반환한 경우"ISA account not found"메시지400 Bad Request상태 코드와 해당 메시지를 반환해야 함mockRejectedValue)500 Internal Server Error상태 코드와"Database error"메시지를 반환해야 함📸 스크린샷
npx jest __tests__/services/challenge-status.test.tsnpx jest __tests__/services/challenge-claim.test.tsnpx jest __tests_/api/challenge-claim-api.test.ts