Autumn Test Suite
This directory contains all tests for the Autumn server application.
Quick Start
# Run setup to initialize the test organization
bun tests setup
# Run a specific test group
bun tests g1
# Run a test group with setup
bun tests g1 setup
# Run a specific test file (fuzzy matching)
bun tests basic1
Test Structure
Test Organization
Tests are organized into logical groups that can be run via shell scripts in server/shell/:
g1.sh- Check API testsg2.sh- Attach API tests (basic, upgrade, downgrade)g3.sh- Attach API tests (checkout, entities, free, addOn)g4.sh- Product and pricing testsg5.sh- Customer and subscription testsg6.sh- Reward and referral tests
Test Files
- setupMain.ts - Main setup script that clears and initializes the test organization
- global.ts - Shared test data (features, products, rewards, etc.)
- utils/ - Test utilities and helper functions
setupUtils/clearOrg.ts- Clears test org datasetupUtils/setupOrg.ts- Sets up test org with features and productssetup.ts- Re-exports setup utilitiesinit.ts- Test initialization helpersstripeUtils.ts- Stripe-specific test utilities
Test Setup Process
The setup process (setupMain.ts) does the following:
-
Clears the test organization (
clearOrg):- Reconnects Stripe with test credentials
- Resets the default Stripe account (automatically removes all Stripe resources)
- Deletes all customers from database
- Deletes all products from database
- Deletes all rewards from database
- Deletes all features from database
-
Sets up the test organization (
setupOrg):- Creates all test features
- Creates all test products with pricing and entitlements
- Creates all test rewards/coupons
- Creates all reward triggers (referral programs)
- Initializes Stripe products if running in parallel mode
Running Tests
Setup Command
The setup command runs the setupMain.ts script to initialize the test environment:
bun tests setup
This is required before running any tests to ensure a clean state.
Shell Scripts
Shell scripts in server/shell/ define test groups. Each script:
- Can run setup automatically if "setup" is passed as an argument
- Runs multiple test files in parallel or serial mode
- Uses configuration from
server/shell/config.sh
Example:
# Run g1 tests with setup
bun tests g1 setup
# Run g1 tests without setup (assumes setup was already run)
bun tests g1
Individual Test Files
You can run individual test files by name (fuzzy matching):
# Runs the first matching test file
bun tests basic1
# Runs with path pattern
bun tests attach/basic1
The test runner will:
- Search for matching test files
- Automatically detect if it's a Bun test or Mocha test
- Run with the appropriate test runner
Test Frameworks
Tests can use either:
- Bun Test - Files with
from "bun:test"import (faster) - Mocha - Traditional mocha tests (legacy)
The test runner auto-detects which framework to use based on imports.
Environment Variables
Required environment variables for tests:
TESTS_ORG- Test organization slug (e.g., "unit-test-org")TESTS_ORG_ID- Test organization IDSTRIPE_TEST_KEY- Stripe test secret keyUNIT_TEST_AUTUMN_SECRET_KEY- Autumn API secret key for testsUNIT_TEST_AUTUMN_PUBLIC_KEY- Autumn API public key for tests
Configuration
Test configuration is defined in server/shell/config.sh:
MOCHA_SETUP="bun tests/setupMain.ts"
MOCHA_CMD="bunx mocha --parallel -j 6 --timeout 10000000 --ignore tests/00_setup.ts"
BUN_CMD="bun test --concurrent"
Best Practices
- Always run setup first - Use
bun tests setuporbun tests <group> setupto ensure clean state - Use parallel execution - Set
MOCHA_PARALLEL=truefor faster test runs - Isolate test data - Each test should be independent and not rely on other tests
- Clean up resources - Tests should clean up any resources they create
- Use descriptive names - Test files should have clear, descriptive names
Internal API Endpoints
The test suite uses internal API endpoints for efficiency:
POST /organization/reset_default_account- Resets the default Stripe account (clears all Stripe data)- Only works for
TESTS_ORG_ID - Only works in sandbox environment
- Faster than manually deleting Stripe resources
- Only works for
Troubleshooting
Tests failing with "Org not found"
Run setup: bun tests setup
Stripe errors
Check that STRIPE_TEST_KEY is set correctly
Cache issues
The setup script automatically invalidates cache for test API keys
Parallel execution issues
If tests interfere with each other, try running in serial mode by setting MOCHA_PARALLEL=false