All files / libs/payout-definition/challenges/shared/src/lib get-challenge-status.ts

85.71% Statements 12/14
20% Branches 1/5
100% Functions 1/1
85.71% Lines 12/14

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 151x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x   1x  
import { type UnixTimestampInSeconds } from '@amalia/ext/dates';
import { type RuleConfiguration } from '@amalia/payout-definition/plans/types';
 
export type ChallengeStatus = 'future' | 'ongoing' | 'past';
 
export const getChallengeStatus = (
  ruleConfiguration?: Pick<RuleConfiguration, 'challengeEndDate' | 'challengeStartDate'> | null,
  referenceDate: UnixTimestampInSeconds = Date.now() / 1000,
): ChallengeStatus =>
  ruleConfiguration?.challengeStartDate && ruleConfiguration.challengeStartDate > referenceDate
    ? 'future'
    : ruleConfiguration?.challengeEndDate && ruleConfiguration.challengeEndDate < referenceDate
      ? 'past'
      : 'ongoing';