This document describes the comprehensive integration test suite for the StellarStream backend API.
The integration tests cover all major REST API flows including:
- Stream lifecycle (create, list, get, cancel)
- Filtering and pagination
- Event history tracking
- Export functionality
- Error handling
Tests use a separate SQLite database (test-streams.db) to ensure:
- No interference with development data
- Clean state for each test
- Isolated test environment
The test database is automatically:
- Created before tests run
- Cleaned between each test
- Deleted after all tests complete
# Run all tests
npm test
# Run integration tests only
npm test integration.test.ts
# Run tests in watch mode
npm test -- --watch
# Run tests with coverage
npm test -- --coverage- ✅ Service status endpoint
- ✅ List all streams
- ✅ Filter by status (scheduled, active, completed, canceled)
- ✅ Filter by sender
- ✅ Filter by recipient
- ✅ Filter by asset
- ✅ Search by query string
- ✅ Pagination (page, limit)
- ✅ Validation errors (invalid status, page, limit)
- ✅ Get specific stream
- ✅ 404 for non-existent stream
- ✅ 400 for invalid stream ID
- ✅ Get streams for recipient
- ✅ Empty array for recipient with no streams
- ✅ 400 for invalid account ID
- ✅ Get streams for sender
- ✅ Filter by status
- ✅ Pagination
- ✅ 400 for invalid account ID
- ✅ Get event history for stream
- ✅ 404 for non-existent stream
- ✅ Get stream with history
- ✅ 404 for non-existent stream
- ✅ List all events
- ✅ Filter by event type
- ✅ Pagination
- ✅ 400 for invalid event type
- ✅ Export all streams as CSV
- ✅ Filter by status
- ✅ Filter by asset
- ✅ Filter by sender
- ✅ Correct CSV format and headers
- ✅ Graceful handling of database errors
- ✅ Proper error messages and status codes
Each test suite follows this pattern:
describe("Feature", () => {
beforeEach(() => {
// Setup test data
});
it("should handle expected behavior", async () => {
const response = await request(app).get("/api/endpoint");
expect(response.status).toBe(200);
// Additional assertions
});
it("should handle error cases", async () => {
const response = await request(app).get("/api/invalid");
expect(response.status).toBe(400);
// Error assertions
});
});- Uses separate test database
- No impact on development data
- Clean state between tests
- Happy path scenarios
- Error cases
- Edge cases
- Validation errors
- Uses supertest for actual HTTP calls
- Tests full request/response cycle
- Validates headers, status codes, and body
- Tests actual database operations
- Verifies data persistence
- Tests transactions and constraints
When adding new endpoints or features:
- Add test data setup in
beforeEach - Test happy path first
- Add error case tests
- Test edge cases
- Verify validation
Example:
describe("New Feature", () => {
beforeEach(() => {
// Insert test data
});
it("should handle valid request", async () => {
const response = await request(app)
.post("/api/new-endpoint")
.send({ data: "valid" });
expect(response.status).toBe(201);
expect(response.body.data).toBeDefined();
});
it("should reject invalid request", async () => {
const response = await request(app)
.post("/api/new-endpoint")
.send({ data: "invalid" });
expect(response.status).toBe(400);
expect(response.body.error).toBeDefined();
});
});These tests are designed to run in CI/CD pipelines:
- Fast execution
- No external dependencies
- Deterministic results
- Clean setup and teardown
- Ensure dependencies are installed:
npm install - Check that no other process is using the test database
- Verify environment variables are not interfering
If you see "database is locked" errors:
- Ensure previous test runs completed
- Delete
backend/data/test-streams.dbmanually - Restart the test suite
Tests use the Express app directly (no port binding), so port conflicts should not occur.
Potential additions to the test suite:
- Authentication flow tests
- Webhook delivery tests
- Concurrent request handling
- Performance benchmarks
- Load testing