All files / lib/testimonials verification.ts

100% Statements 72/72
100% Branches 10/10
100% Functions 4/4
100% Lines 72/72

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115                                              3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x         3x 24x 24x         3x 13x 13x 13x         3x 6x 4x 4x         3x 3x 3x 3x 3x 3x 3x 3x 3x 3x       3x 9x 9x 9x  
/**
 * Testimonial Verification Logic
 *
 * Handles verification levels and badge display for testimonials
 */
 
export type TestimonialVerificationType =
  | 'unverified'
  | 'email_verified'
  | 'identity_linked'
  | 'domain_verified'
  | 'work_verified';
 
export interface VerificationLevel {
  type: TestimonialVerificationType;
  label: string;
  description: string;
  color: string;
  bgColor: string;
  borderColor: string;
  priority: number;
}
 
export const VERIFICATION_LEVELS: Record<TestimonialVerificationType, VerificationLevel> = {
  unverified: {
    type: 'unverified',
    label: 'Unverified',
    description: 'This testimonial has not been verified',
    color: 'text-gray-500',
    bgColor: 'bg-gray-100 dark:bg-gray-800',
    borderColor: 'border-gray-200 dark:border-gray-700',
    priority: 0,
  },
  email_verified: {
    type: 'email_verified',
    label: 'Email Verified',
    description: 'Author verified their email address',
    color: 'text-blue-600',
    bgColor: 'bg-blue-50 dark:bg-blue-950/30',
    borderColor: 'border-blue-200 dark:border-blue-800',
    priority: 1,
  },
  identity_linked: {
    type: 'identity_linked',
    label: 'Identity Linked',
    description: 'Author is a verified ProofID user',
    color: 'text-purple-600',
    bgColor: 'bg-purple-50 dark:bg-purple-950/30',
    borderColor: 'border-purple-200 dark:border-purple-800',
    priority: 2,
  },
  domain_verified: {
    type: 'domain_verified',
    label: 'Domain Verified',
    description: 'Author verified through company email domain',
    color: 'text-emerald-600',
    bgColor: 'bg-emerald-50 dark:bg-emerald-950/30',
    borderColor: 'border-emerald-200 dark:border-emerald-800',
    priority: 3,
  },
  work_verified: {
    type: 'work_verified',
    label: 'Work Verified',
    description: 'Author verified through work relationship',
    color: 'text-amber-600',
    bgColor: 'bg-amber-50 dark:bg-amber-950/30',
    borderColor: 'border-amber-200 dark:border-amber-800',
    priority: 4,
  },
};
 
/**
 * Get verification level info
 */
export function getVerificationLevel(type: string): VerificationLevel {
  return VERIFICATION_LEVELS[type as TestimonialVerificationType] || VERIFICATION_LEVELS.unverified;
}
 
/**
 * Check if verification is meaningful (higher than unverified)
 */
export function isVerified(type: string): boolean {
  const level = getVerificationLevel(type);
  return level.priority > 0;
}
 
/**
 * Get verification badge text
 */
export function getVerificationBadgeText(type: string): string | null {
  if (!isVerified(type)) return null;
  return getVerificationLevel(type).label;
}
 
/**
 * Relationship context options
 */
export const RELATIONSHIP_CONTEXTS = [
  { value: 'client', label: 'Client' },
  { value: 'colleague', label: 'Colleague' },
  { value: 'manager', label: 'Manager' },
  { value: 'direct_report', label: 'Direct Report' },
  { value: 'vendor', label: 'Vendor/Partner' },
  { value: 'student', label: 'Student' },
  { value: 'mentor', label: 'Mentor' },
  { value: 'other', label: 'Other' },
] as const;
 
export type RelationshipContext = (typeof RELATIONSHIP_CONTEXTS)[number]['value'];
 
export function getRelationshipLabel(context: string): string {
  const found = RELATIONSHIP_CONTEXTS.find((r) => r.value === context);
  return found?.label || context;
}