This document describes the end-to-end (E2E) testing suite for the Stellar Invoice Financing Platform. The E2E tests validate the complete user journey from authentication through settlement.
- E2E Tests:
tests/e2e/full-flow.e2e.test.ts - Test Runner: Jest with Supertest
- Database: SQLite in-memory (with PostgreSQL compatibility patches)
The E2E test validates the following user journey:
-
Authentication (4 tests)
- Seller registers via Stellar challenge-response
- Investor registers via Stellar challenge-response
- KYC approval for seller (required for invoice publishing)
- KYC approval for investor (required for investments)
-
Invoice Creation & Publishing (4 tests)
- Seller creates invoice
- Document upload to IPFS (mocked)
- Invoice publishing
- Database state verification
-
Marketplace Listing (1 test)
- Published invoices appear in marketplace
- Sensitive data is not exposed
-
Investment Creation (3 tests)
- Investor creates investment
- Invoice transitions to FUNDED status
- Database state verification
-
Investment Confirmation (1 test)
- Simulates Horizon blockchain verification
- Investment status transitions to CONFIRMED
-
Settlement (4 tests)
- Invoice settlement with pro-rata distribution
- Invoice transitions to SETTLED
- Investment transitions to SETTLED
- Investor dashboard reflects returns
-
Post-Settlement Verification (3 tests)
- Settled invoice cannot be updated
- Settled invoice cannot receive new investments
- Complete flow integrity check
Total: 20 tests
npm run test:e2enpm testnpx jest tests/e2e/full-flow.e2e.test.tsThe E2E tests use SQLite in-memory for fast execution, but the production code uses PostgreSQL. To bridge this gap:
-
Metadata Patching: Before initializing the database, we patch TypeORM entity metadata to convert PostgreSQL-specific types to SQLite equivalents:
timestamptz→datetimejsonb→textenum→varchar
-
Decimal Handling: SQLite returns decimals as numbers instead of strings. The test suite uses a
toNum()helper function to normalize values for comparison. -
Row Locking: SQLite doesn't support pessimistic row locking. The
InvestmentServiceandSettlementServicehave been updated to gracefully fall back to non-locked queries when locking is unavailable.
- IPFS: Mocked to return deterministic hashes (
QmMockHash...) - Stellar Horizon: Simulated by directly updating database records
- Email Notifications: Not tested in E2E (covered by unit tests)
The tests use real Stellar keypairs for authentication:
- Seller and investor each have their own keypair
- Challenge-response flow is tested end-to-end
- JWT tokens are generated and used for subsequent requests
- Added
userIdto JWT payload alongsidestellarAddress - Enables proper user identification in stateless middleware
- Updated
authenticateJWTto useuserIdfrom JWT payload - Falls back to
stellarAddressfor backward compatibility
- Added try-catch fallback for pessimistic locking
- Gracefully handles databases that don't support row locks
- Added error code to error message for better test assertions
- Format:
"INVALID_INVOICE_STATUS: Cannot settle an invoice with status..."
- Updated
decimalStringToScaledBigIntto accept bothstringandnumber - Ensures compatibility with SQLite's decimal handling
The E2E test uses the following test data:
- Invoice Amount: 10,000 XLM
- Discount Rate: 5%
- Net Amount: 9,500 XLM
- Investment Amount: 9,500 XLM (full funding)
- Settlement Proceeds: 10,000 XLM
- Expected Return: 10,000 XLM
- Profit: 500 XLM (5% return)
The E2E test sets the following environment variables:
JWT_SECRET: Test JWT secretADMIN_API_KEY: Test admin API keySKIP_KYC_VERIFICATION:true(bypasses KYC middleware)
The E2E tests are designed to run in CI/CD pipelines:
- No external dependencies (database, IPFS, Stellar)
- Fast execution (~3-4 seconds)
- Deterministic results
- No real secrets required
This error indicates the database doesn't support pessimistic locking. The code has been updated to handle this gracefully. If you see this error, ensure you're using the latest version of the service files.
This error occurs when SQLite returns decimal values as numbers instead of strings. The decimalStringToScaledBigInt function has been updated to handle both types.
This error indicates the invoice is not in the expected state. Check the test flow to ensure all previous steps completed successfully.
Potential enhancements for the E2E test suite:
- Multi-Investor Scenarios: Test partial funding with multiple investors
- Error Recovery: Test system behavior when operations fail mid-flow
- Concurrent Operations: Test race conditions in investment creation
- Performance Testing: Measure response times for each operation
- PostgreSQL Testing: Add optional PostgreSQL test configuration for CI
- Testing Strategy - Overall testing approach
- API Documentation - API endpoint reference
- Architecture - System architecture overview