[TEST] Build Comprehensive Test Infrastructure
Priority: Medium
Difficulty: Hard
Estimated Effort: 3-4 days
Relevant Packages: OrbitStream_backend/
Labels: testing, enhancement, priority:medium
Requirements
1. Fix Smoke Test
- Rewrite
app.smoke.spec.ts to use @nestjs/testing Test.createTestingModule
- Test that the app module compiles successfully
- Test that the health endpoint is registered
2. Test Infrastructure
Create a test infrastructure that supports:
Database Testing
- Use an in-memory SQLite database for unit tests (or a test PostgreSQL database)
- Create a
TestDbModule that provides a clean database for each test
- Seed test data: merchants, API keys, sessions, payments
- Clean up after each test (truncate all tables)
HTTP Testing
- Use
@nestjs/testing Test.createTestingModule with INestApplication
- Use
supertest for HTTP assertions
- Create a
createTestApp() helper that sets up the app with mocked dependencies
- Apply
ValidationPipe and CORS middleware to the test app
Stellar Mocking
- Create a
StellarServiceMock that implements the same interface as StellarService
- Mock Horizon responses for: account info, payment history, transaction verification
- Use
nock or msw to intercept HTTP calls to Horizon
- Create fixture files with realistic Horizon response data
Auth Testing
- Create a
TestAuthModule that provides mock JWT tokens
- Create a
getAuthToken(merchantId) helper for authenticated tests
- Create a
getApiKey(merchantId) helper for API key tests
3. Integration Tests
Create integration tests for the full payment flow:
Test: Create Checkout Session
1. Generate API key for test merchant
2. POST /v1/checkout/sessions with API key
3. Assert 201 response with session ID and URL
4. Assert session exists in database with status "pending"
Test: Get Session Status
1. Create a session
2. GET /v1/checkout/sessions/:id
3. Assert 200 response with status "pending"
Test: Cancel Session
1. Create a session
2. POST /v1/checkout/sessions/:id/cancel with API key
3. Assert 200 response
4. Assert session status is "cancelled"
Test: Full Payment Flow
1. Create a session
2. Mock Horizon to return a payment with matching memo
3. Wait for payment detector to process (or trigger manually)
4. Assert session status is "paid"
5. Assert payment record exists
6. Assert webhook was dispatched (verify with mock HTTP server)
Test: Auth Flow
1. POST /auth/challenge with wallet address
2. Mock Stellar signature verification
3. POST /auth/verify with signed challenge
4. Assert JWT token returned
5. Use JWT to access protected endpoint
4. Unit Tests for Underserved Modules
Write unit tests for:
CheckoutService: create session, get session, cancel session, auto-expire
PaymentDetectorService: process payment, amount mismatch, asset mismatch
WebhookService: dispatch, retry, HMAC signing
MerchantsService: register, find, API key generation, webhook config
StellarService: getAccountInfo, getBalance, verifyTransaction
5. Test Configuration
- Update
jest.config.ts to include integration test patterns
- Add
test:unit and test:integration npm scripts
- Add
test:coverage script with coverage thresholds (>80% for auth, checkout, payments)
- Create
src/__tests__/fixtures/ directory for test data
[TEST] Build Comprehensive Test Infrastructure
Priority: Medium
Difficulty: Hard
Estimated Effort: 3-4 days
Relevant Packages:
OrbitStream_backend/Labels:
testing,enhancement,priority:mediumRequirements
1. Fix Smoke Test
app.smoke.spec.tsto use@nestjs/testingTest.createTestingModule2. Test Infrastructure
Create a test infrastructure that supports:
Database Testing
TestDbModulethat provides a clean database for each testHTTP Testing
@nestjs/testingTest.createTestingModulewithINestApplicationsupertestfor HTTP assertionscreateTestApp()helper that sets up the app with mocked dependenciesValidationPipeand CORS middleware to the test appStellar Mocking
StellarServiceMockthat implements the same interface asStellarServicenockormswto intercept HTTP calls to HorizonAuth Testing
TestAuthModulethat provides mock JWT tokensgetAuthToken(merchantId)helper for authenticated testsgetApiKey(merchantId)helper for API key tests3. Integration Tests
Create integration tests for the full payment flow:
Test: Create Checkout Session
Test: Get Session Status
Test: Cancel Session
Test: Full Payment Flow
Test: Auth Flow
4. Unit Tests for Underserved Modules
Write unit tests for:
CheckoutService: create session, get session, cancel session, auto-expirePaymentDetectorService: process payment, amount mismatch, asset mismatchWebhookService: dispatch, retry, HMAC signingMerchantsService: register, find, API key generation, webhook configStellarService: getAccountInfo, getBalance, verifyTransaction5. Test Configuration
jest.config.tsto include integration test patternstest:unitandtest:integrationnpm scriptstest:coveragescript with coverage thresholds (>80% for auth, checkout, payments)src/__tests__/fixtures/directory for test data