All files / marketing-platform/domain/exceptions PromotionExceptions.ts

83.33% Statements 10/12
71.42% Branches 5/7
80% Functions 8/10
83.33% Lines 10/12

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          27x 27x 27x                 5x                                   3x                 3x                 2x                 11x                 1x                                   2x      
/**
 * Base class for all promotion-related domain exceptions
 */
export abstract class PromotionDomainException extends Error {
  constructor(message: string) {
    super(message);
    this.name = this.constructor.name;
    Object.setPrototypeOf(this, new.target.prototype);
  }
}
 
/**
 * Thrown when promotion dates are invalid
 */
export class InvalidPromotionDateException extends PromotionDomainException {
  constructor(message: string = 'Invalid promotion date: start date must be before end date') {
    super(message);
  }
}
 
/**
 * Thrown when a promotion is not active
 */
export class PromotionNotActiveException extends PromotionDomainException {
  constructor(message: string = 'Promotion is not currently active') {
    super(message);
  }
}
 
/**
 * Thrown when budget or quantity constraints are violated
 */
export class InsufficientBudgetException extends PromotionDomainException {
  constructor(message: string = 'Insufficient budget or quantity remaining') {
    super(message);
  }
}
 
/**
 * Thrown when payment amount doesn't meet minimum requirements
 */
export class MinimumPaymentNotMetException extends PromotionDomainException {
  constructor(minimumRequired: number, actualAmount: number) {
    super(`Payment amount ${actualAmount} does not meet minimum requirement of ${minimumRequired}`);
  }
}
 
/**
 * Thrown when percentage values are out of valid range
 */
export class InvalidPercentageException extends PromotionDomainException {
  constructor(value: number) {
    super(`Invalid percentage value: ${value}. Must be between 0 and 100.`);
  }
}
 
/**
 * Thrown when coupon quantity is invalid
 */
export class InvalidCouponQuantityException extends PromotionDomainException {
  constructor(message: string = 'Invalid coupon quantity') {
    super(message);
  }
}
 
/**
 * Thrown when attempting to use an expired coupon
 */
export class CouponExpiredException extends PromotionDomainException {
  constructor(message: string = 'Coupon has expired') {
    super(message);
  }
}
 
/**
 * Thrown when download limit is exceeded
 */
export class DownloadLimitExceededException extends PromotionDomainException {
  constructor(message: string = 'Download limit has been exceeded') {
    super(message);
  }
}
 
/**
 * Thrown when point calculation is invalid
 */
export class InvalidPointCalculationException extends PromotionDomainException {
  constructor(message: string = 'Invalid point calculation') {
    super(message);
  }
}