Skip to content

Task 3-1: Integration Test - Rental Lifecycle

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 toàn bộ rental lifecycle: create → verify → confirm → finish/cancel/return.

Test scenarios

Happy path: Create → Verify → Confirm → Expire

  • [ ] POST /api/nft-rental với bountyBallId (product status=AVAILABLE) → order status=NEW, product status=RENTING
  • [ ] PUT /verify-order-creation/{id} với valid transactionHashstatus=NEW_VERIFIED
  • [ ] PUT /confirm-rent/{id} (as renter) → renter B-Coin deducted, owner credited, status=RENTING
  • Verify: renter balance giảm đúng rentalFee
  • Verify: owner balance tăng đúng rentalFee - adminFee
  • [ ] Simulate expiry → NftRentalExpirationCheckBatch chạy → status=FINISHED, product status=AVAILABLE

Cancel flow

  • [ ] PUT /cancel-rental-order/{id} khi status=NEWstatus=CANCELLED, product status=AVAILABLE
  • [ ] PUT /cancel-rental-order/{id} khi status=RENTING → error (không cho phép cancel khi đang renting)
  • [ ] Verify: B-Coin không bị deduct khi cancel từ status=NEW

Return early

  • [ ] PUT /return-rental-early/{id} khi đang RENTINGstatus=RETURN_EARLY
  • [ ] Verify pro-rated refund: renter nhận lại portion coin chưa dùng
  • [ ] Verify owner nhận coin cho thời gian đã dùng
  • [ ] Notification gửi tới owner: "NFT returned early"

Concurrent confirm (liên quan task-1-2)

  • [ ] 2 renters gọi confirm-rent/{id} đồng thời → chỉ 1 thành công, 1 nhận RENTAL_ORDER_NOT_AVAILABLE
  • [ ] Kiểm tra: không có double charge (verify balance chỉ bị deduct 1 lần)

Market listing

  • [ ] GET /market-rental (as owner) → không hiển thị listings của chính owner
  • [ ] GET /market-rental (as other user) → hiển thị listing của owner

Minted NFT path

  • [ ] Confirm rent với minted Bounty Ball → NodeServerService.confirmSolanaNftRental() được gọi
  • [ ] Confirm rent với unminted Bounty Ball → chỉ DB update, không call NodeServer

Verification / Acceptance Criteria

  • [ ] Happy path: tất cả status transitions đúng (NEWNEW_VERIFIEDRENTINGFINISHED)
  • [ ] B-Coin balance: deduct và credit đúng amount (bao gồm admin fee)
  • [ ] Cancel: chỉ cho phép từ NEW, không từ RENTING
  • [ ] Market listing: owner không thấy listing của chính mình
  • [ ] Minted vs unminted: NodeServerService được gọi đúng theo điều kiện
  • [ ] Test endpoints finish-rental-ordertest-change-owner trả 404 khi chạy với profile main (liên quan task-1-1)

Files to Modify

  • Test files trong webmarketplace/src/test/ hoặc integration test module