Skip to content

Latest commit

 

History

History
432 lines (344 loc) · 9.92 KB

File metadata and controls

432 lines (344 loc) · 9.92 KB

🚀 Double Down on DX (Developer Experience)

MockAuth is designed with developers in mind. This document showcases the enhanced developer experience features that make authentication testing and development a breeze.

🎯 Core DX Principles

1. Zero Configuration Start

Get up and running in seconds, not minutes.

# One command to rule them all
npx mockauth init --quick-start

# Or even simpler
npx mockauth start --auto-config

2. Intelligent Defaults

Smart defaults that work out of the box, but are easily customizable.

// This just works!
const auth = new MockAuth({
  port: 3001,
  jwtSecret: 'dev-secret' // That's it!
});

// But you can customize everything
const auth = new MockAuth({
  port: 3001,
  jwtSecret: 'dev-secret',
  users: [
    { email: 'admin@test.com', password: 'admin123', roles: ['admin'] },
    { email: 'user@test.com', password: 'user123', roles: ['user'] }
  ],
  features: {
    mfa: true,
    passwordReset: true,
    accountLockout: true
  }
});

3. Visual Configuration Builder

No more guessing configuration options. Use our web-based builder.

# Launch the visual builder
npx mockauth builder

# Or with custom port
npx mockauth builder --port 3002

Builder Features:

  • 🎨 Drag-and-drop user management
  • 🔧 Real-time configuration preview
  • 📊 Visual role and permission mapping
  • 🧪 Test scenarios builder
  • 📤 Export configuration as code

4. Smart CLI with Auto-completion

Intelligent command-line interface with suggestions and help.

# Auto-completion setup
npx mockauth setup-completion

# Now you get smart suggestions
npx mockauth <TAB> # Shows all available commands
npx mockauth user <TAB> # Shows user-related commands
npx mockauth user create <TAB> # Shows create options

5. Hot Reload & Live Updates

See changes instantly without restarting.

// Enable hot reload
const auth = new MockAuth({
  port: 3001,
  hotReload: true, // 🔥 Changes apply instantly
  watchConfig: true // 👀 Watch config file changes
});

// Add users on the fly
auth.addUser({
  email: 'newuser@test.com',
  password: 'password123',
  roles: ['user']
}); // ✨ Available immediately!

🛠️ Enhanced Development Tools

1. Interactive Debug Console

Built-in debugging interface for real-time inspection.

# Start with debug console
npx mockauth start --debug

# Access at http://localhost:3001/debug

Debug Console Features:

  • 🔍 Real-time request/response inspection
  • 👥 Live user session monitoring
  • 🔐 Token validation and debugging
  • 📊 Performance metrics dashboard
  • 🧪 API testing playground

2. Smart Test Data Generation

Automatically generate realistic test data.

// Auto-generate test users
const auth = new MockAuth({
  port: 3001,
  autoGenerateUsers: {
    count: 50,
    roles: ['admin', 'user', 'moderator'],
    realisticData: true // Generate realistic names, emails, etc.
  }
});

// Or generate specific scenarios
auth.generateTestScenario('ecommerce', {
  users: 100,
  roles: ['customer', 'seller', 'admin'],
  permissions: ['buy', 'sell', 'manage']
});

3. Framework-Specific Boilerplates

Pre-built integrations for popular frameworks.

# Generate React integration
npx mockauth generate --framework react --output ./src/auth

# Generate Vue integration  
npx mockauth generate --framework vue --output ./src/auth

# Generate Angular integration
npx mockauth generate --framework angular --output ./src/auth

4. Visual API Documentation

Auto-generated, interactive API docs.

# Generate API documentation
npx mockauth docs --format interactive

# Access at http://localhost:3001/docs

Features:

  • 🎮 Interactive API testing
  • 📝 Auto-generated examples
  • 🔍 Searchable endpoints
  • 📊 Request/response schemas

🧪 Testing Made Simple

1. One-Line Test Setup

// Jest integration
import { createMockAuth } from 'mockauth/testing';

describe('Auth Flow', () => {
  let auth;
  
  beforeEach(async () => {
    // One line setup!
    auth = await createMockAuth({
      users: [{ email: 'test@example.com', password: 'test123' }]
    });
  });
  
  afterEach(async () => {
    await auth.cleanup(); // Auto-cleanup
  });
  
  test('should login user', async () => {
    const result = await auth.login('test@example.com', 'test123');
    expect(result.success).toBe(true);
  });
});

2. Cypress Integration

// cypress/support/mockauth.js
import 'mockauth/cypress';

// Now you can use:
cy.mockAuthLogin('admin@test.com', 'admin123');
cy.mockAuthLogout();
cy.mockAuthUser('admin'); // Predefined user

3. Playwright Integration

// playwright.config.js
import { mockAuth } from 'mockauth/playwright';

export default {
  use: {
    ...mockAuth({
      baseUrl: 'http://localhost:3001',
      users: [
        { email: 'admin@test.com', password: 'admin123', roles: ['admin'] }
      ]
    })
  }
};

🎨 Visual Development Experience

1. Real-time Dashboard

Monitor your auth system in real-time.

# Start with dashboard
npx mockauth start --dashboard

# Access at http://localhost:3001/dashboard

Dashboard Features:

  • 📊 Live metrics and statistics
  • 👥 Active user sessions
  • 🔐 Token lifecycle visualization
  • 🚨 Security alerts and warnings
  • 📈 Performance monitoring

2. Visual User Management

Manage users through an intuitive interface.

# Launch user management UI
npx mockauth users --ui

# Features:
# - Add/remove users with forms
# - Role and permission assignment
# - Bulk user operations
# - User activity timeline

3. API Testing Playground

Test your APIs without leaving the browser.

# Launch API playground
npx mockauth playground

# Features:
# - Interactive API testing
# - Request/response inspection
# - Authentication flow testing
# - Performance benchmarking

🔧 Advanced DX Features

1. Smart Configuration Validation

// Validate your config before starting
const auth = new MockAuth(config);

// Get detailed validation results
const validation = auth.validateConfig();
if (!validation.valid) {
  console.log('Configuration issues:', validation.errors);
  console.log('Suggestions:', validation.suggestions);
}

2. Automatic Environment Detection

// Automatically adapt to your environment
const auth = new MockAuth({
  // Auto-detects: development, testing, staging
  environment: 'auto', // 🧠 Smart detection
  
  // Auto-configures based on environment
  features: 'auto', // 🔧 Smart defaults
  
  // Auto-scales based on usage
  performance: 'auto' // ⚡ Smart optimization
});

3. Intelligent Error Messages

// Instead of cryptic errors, get helpful messages
try {
  await auth.login('user@test.com', 'wrong-password');
} catch (error) {
  // Error: "Login failed for user@test.com. 
  // This might be because: 1) Wrong password, 2) Account locked, 3) User doesn't exist.
  // Try: auth.unlockUser('user@test.com') or auth.createUser({...})"
  console.log(error.helpfulMessage);
  console.log(error.suggestions);
}

4. Smart Code Generation

# Generate auth service for your framework
npx mockauth generate-service --framework react --output ./src/services/auth.js

# Generates:
# - Complete auth service
# - Type definitions
# - Usage examples
# - Test files

🚀 Performance & Monitoring

1. Built-in Performance Monitoring

const auth = new MockAuth({
  port: 3001,
  monitoring: {
    enabled: true,
    metrics: ['response-time', 'memory-usage', 'request-count'],
    alerts: ['high-latency', 'memory-leak', 'error-rate']
  }
});

// Access metrics
const metrics = auth.getMetrics();
console.log('Response time:', metrics.responseTime);
console.log('Memory usage:', metrics.memoryUsage);

2. Smart Caching

const auth = new MockAuth({
  port: 3001,
  caching: {
    enabled: true,
    strategies: ['user-sessions', 'token-validation', 'role-permissions'],
    ttl: '5m' // Auto-expire cache
  }
});

3. Health Checks & Diagnostics

# Comprehensive health check
npx mockauth health --detailed

# Output:
# ✅ Server: Running on port 3001
# ✅ Database: Connected (PostgreSQL)
# ✅ Memory: 45MB (Normal)
# ✅ Response Time: 12ms (Excellent)
# ✅ Active Sessions: 23
# ⚠️  Warning: High memory usage detected

🎯 Best Practices for DX

1. Development Workflow

# 1. Quick start
npx mockauth init --quick-start

# 2. Configure visually
npx mockauth builder

# 3. Test your integration
npx mockauth test --integration

# 4. Deploy to staging
npx mockauth deploy --environment staging

2. Team Collaboration

# Share configuration
npx mockauth export-config --format json > mockauth.config.json

# Import team configuration
npx mockauth import-config mockauth.config.json

# Version control integration
npx mockauth git-hooks --install

3. CI/CD Integration

# .github/workflows/test.yml
- name: Setup MockAuth
  run: npx mockauth start --background
  
- name: Run Tests
  run: npm test
  
- name: Generate Test Report
  run: npx mockauth test-report --format html

🎉 The MockAuth DX Promise

With MockAuth, you get:

  • Instant Setup - From zero to running in under 30 seconds
  • 🎨 Visual Tools - No more configuration guessing
  • 🧪 Testing Made Easy - One-line test setup
  • 🔍 Smart Debugging - Real-time insights and helpful errors
  • 📊 Live Monitoring - See what's happening in real-time
  • 🚀 Performance First - Built-in optimization and monitoring
  • 🤝 Team Ready - Share configurations and collaborate easily

Ready to experience the best DX in authentication testing?

# Start your journey
npx mockauth init --quick-start

MockAuth: Built by developers, for developers. Because authentication testing shouldn't be painful.