// Test Authentication Utilities
// Helpers for authentication in tests

import jwt from 'jsonwebtoken';
import { JwtPayload } from '@/shared/types';

const TEST_JWT_SECRET = process.env.JWT_SECRET || 'test-jwt-secret-minimum-32-characters-long-for-testing';

/**
 * Create a test JWT token
 */
export function createTestToken(payload: Partial<JwtPayload>): string {
  const defaultPayload: JwtPayload = {
    sovereignBankId: 'test-bank-id',
    identityType: 'API',
    apiRole: 'user',
    iat: Math.floor(Date.now() / 1000),
    exp: Math.floor(Date.now() / 1000) + 3600, // 1 hour
    ...payload,
  };

  return jwt.sign(defaultPayload, TEST_JWT_SECRET);
}

/**
 * Create test request headers with authentication
 */
export function createAuthHeaders(payload?: Partial<JwtPayload>): Record<string, string> {
  const token = createTestToken(payload || {});
  return {
    authorization: `SOV-TOKEN ${token}`,
    'x-sov-signature': 'test-signature',
    'x-sov-timestamp': Date.now().toString(),
    'x-sov-nonce': 'test-nonce',
  };
}

