All files / src/lib demo-mode.ts

100% Statements 43/43
100% Branches 7/7
100% Functions 3/3
100% Lines 43/43

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 94x 94x 3x 3x 3x 91x 91x 91x  
/**
 * Demo Mode Configuration
 *
 * When demo mode is enabled:
 * - Payment processing is skipped (no Stripe charges)
 * - Orders are marked with isDemo: true
 * - Emails include demo mode notice
 * - UI shows demo indicators
 */
 
/**
 * Check if demo mode is enabled (server-side)
 */
export function isDemoMode(): boolean {
  return process.env.NEXT_PUBLIC_DEMO_MODE === "true";
}
 
/**
 * Get full demo mode configuration
 */
export function getDemoModeConfig() {
  const enabled = isDemoMode();
  return {
    enabled,
    skipPayment: enabled,
    emailNotice: enabled
      ? "[DEMO MODE] This is a test order - no payment was processed."
      : null
  };
}
 
/**
 * Check if demo mode is enabled (client-side safe)
 * Use this in client components
 */
export function getClientDemoMode(): boolean {
  if (typeof window === "undefined") {
    // Server-side: check env directly
    return process.env.NEXT_PUBLIC_DEMO_MODE === "true";
  }
  // Client-side: NEXT_PUBLIC_ vars are available
  return process.env.NEXT_PUBLIC_DEMO_MODE === "true";
}