Task 3-3: Integration Test - Return Early & Expiry Batch
Phase: 3 - Testing Priority: Medium Depends on: task-1-1, task-1-2 Reference: docs/BountyHunter-Backend/details/feature-nft-management/SPEC.md
Background
Test các flow kết thúc rental ngoài happy path: renter trả về sớm và batch xử lý expired rentals.
Test scenarios
Return early
- [ ] Create rental → confirm → wait 1 ngày (mock thời gian bằng
Clockinjection hoặc setrental_start_timetrong past) →PUT /return-rental-early/{id} - [ ] Verify:
status=RETURN_EARLY - [ ] Verify pro-rated refund calculation với example cụ thể:
- Duration = 7 ngày, fee = 700
- Return sau 1 ngày → owner giữ 100 (1/7 × 700), renter nhận lại 600 (6/7 × 700)
- Confirm balance changes đúng (owner +100, renter refund +600)
- [ ] Verify: product
status=AVAILABLEsau return - [ ] Verify: owner nhận notification "NFT returned early"
Return early (minted NFT)
- [ ] Return early với minted Bounty Ball →
NodeServerServiceđược gọi để update on-chain state - Mock
NodeServerServicetrong test để verify call và không cần real blockchain - [ ] Return early với unminted → chỉ DB update,
NodeServerServicekhông được gọi
Expiry batch
- [ ] Create rental → confirm → mock expiry (set
rental_end_time= past, ví dụ:Instant.now().minusSeconds(3600)) - [ ] Chạy
NftRentalExpirationCheckBatchmanually (trigger via test context hoặc direct method call) - [ ] Verify:
status=FINISHED(hoặcEXPIRED_HANDLED— xác nhận tên status thực tế trong code) - [ ] Verify: product
status=AVAILABLE - [ ] Verify: notifications sent tới owner và renter
Batch idempotency
- [ ] Chạy batch 2 lần cho cùng expired rental:
- First run: status
RENTING→FINISHED - Second run: status đã
FINISHED→ không thay đổi, không lỗi - [ ] Verify: không có duplicate notifications
Verification / Acceptance Criteria
- [ ] Return early: pro-rated refund tính đúng (owner nhận proportional, renter nhận remainder)
- [ ] Minted NFT return:
NodeServerServiceđược invoke; unminted: không invoke - [ ] Expiry batch: status đúng, product available, notifications sent
- [ ] Batch idempotency: chạy 2+ lần cho cùng record → no-op, no error, no duplicate side effects
- [ ]
rental_end_timeđược set đúng khi confirm (dùng cho expiry check)
Files to Modify
- Test files trong
webmarketplace/src/test/hoặc integration test module