All files / src/features/transactions rules.ts

100% Statements 5/5
100% Branches 4/4
100% Functions 1/1
100% Lines 5/5

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                        52x 2x   50x 2x   48x    
// Date rules for entries (openspec: transactions), checked by the form and
// again on the server against today in Finland and the flat's first
// ownership start. Pure.
import type { IsoDate } from '#/lib/dates'
 
export type TransactionDateProblem =
  'transaction_date_in_future' | 'transaction_date_before_ownership'
 
export function validateTransactionDate(
  date: IsoDate,
  limits: { today: IsoDate; ownershipStart: IsoDate },
): TransactionDateProblem | undefined {
  if (date > limits.today) {
    return 'transaction_date_in_future'
  }
  if (date < limits.ownershipStart) {
    return 'transaction_date_before_ownership'
  }
  return undefined
}