-
Notifications
You must be signed in to change notification settings - Fork 10
Description
➡️ Title
Test end-to-end coupon emission and redemption flow
📘 Description
Create comprehensive end-to-end tests that simulate the complete coupon lifecycle: token purchase → automatic coupon emission → coupon redemption. Verify the entire flow works correctly including contract interactions, database updates, and expiration handling.
Context: Ensure the complete coupon system works as expected by testing the full user journey from purchasing project tokens to redeeming tourism coupons, including all edge cases and error scenarios.
✅ Acceptance Criteria
Test file creation
- Create
src/test/coupon-e2e.test.tsfor end-to-end coupon tests - Set up test environment with clean database state
- Configure Soroban testnet contract deployments
- Prepare test data for users, projects, and business partners
Token purchase to coupon emission flow
- Test complete flow: purchase project token → automatic coupon generation
- Verify coupon NFT is minted on Soroban contract
- Validate coupon metadata is uploaded to IPFS
- Confirm coupon record is created in database
- Check all relationships (user, project, purchase) are correctly linked
Coupon redemption flow
- Test valid coupon redemption process
- Verify contract redeem_coupon() function is called
- Confirm database status is updated to 'redeemed'
- Validate redemption timestamp is recorded
- Check that redeemed coupons cannot be redeemed again
Expiration handling tests
- Test coupon expiration validation
- Verify expired coupons cannot be redeemed
- Test edge case: redemption attempt at exact expiration time
- Validate contract properly handles expired redemption attempts
Error scenario testing
- Test redemption of non-existent coupon
- Test redemption by unauthorized user
- Test contract call failures and rollback behavior
- Test IPFS metadata fetch failures
- Test database connection failures during flow
Performance and concurrency
- Test multiple simultaneous coupon generations
- Test concurrent redemption attempts for same coupon
- Validate database transaction isolation
- Test system behavior under load
Data integrity validation
- Verify coupon token IDs are unique across all coupons
- Confirm metadata integrity between IPFS and database
- Validate contract state matches database state
- Test data consistency after partial failures
Cleanup and utilities
- Create test utilities for setting up coupon scenarios
- Implement cleanup functions for test data
- Add helper functions for contract state verification
- Create mock business partner data for testing
⚠ Use kebab-case for all file and folder names.
⚠ Do not use default alias imports or relative paths like ../../components/foo.
⚠ Use alias paths with @, e.g. @/components/foo.
⚠ Structure the code with reusable components and reuse existing ones.