All files / libs/plan-agreements/shared/src/lib/business-rules/assignments/is-assignment-regenerable is-assignment-regenerable.ts

94.73% Statements 18/19
66.66% Branches 6/9
100% Functions 2/2
100% Lines 17/17

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 181x 1x 1x 1x 1x 1x 1x 1x 142x 145x 145x 145x 145x 145x 3x 2x 1x  
import {
  PlanAgreementAssignmentErrorType,
  PlanAgreementAssignmentStatus,
  PlanAgreementStatus,
  type PlanAgreement,
  type PlanAgreementAssignment,
} from '@amalia/plan-agreements/types';
 
export const isPlanAgreementAssignmentRegenerable = (
  planAgreement: Pick<PlanAgreement, 'status'>,
  assignment: Pick<PlanAgreementAssignment, 'error' | 'sentDate' | 'status'>,
): boolean =>
  // Agreement must be in error state or already finalized and not sent
  (assignment.error?.type === PlanAgreementAssignmentErrorType.GENERATION_ERROR ||
    (planAgreement.status === PlanAgreementStatus.FINALIZED && !assignment.sentDate)) &&
  // Disable regeneration for agreements that are already in the process of being regenerated
  assignment.status !== PlanAgreementAssignmentStatus.AGREEMENT_TO_GENERATE;