All files / app/src/features/validator/validate-objects/lib validate-statuses.ts

50% Statements 9/18
66.66% Branches 4/6
100% Functions 1/1
50% Lines 9/18

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        1x 4x 4x 4x 4x 4x 3x 4x                   4x  
import { SelectedAccountingObject } from '@/entities/accounting-object'
import { PipeStatusEnum } from '@/entities/pipe'
import { OperationsStatus } from './types'
 
export const validateStatuses = (
  operation: OperationsStatus,
  obj: SelectedAccountingObject,
  packageObjects?: SelectedAccountingObject[]
) => {
  if (!operation.availableStatuses.includes(obj.status as PipeStatusEnum) && obj.status) {
    return true
  } else if (obj.packageId && !obj.status) {
    if (packageObjects) {
      const isNotValid = !packageObjects?.every(object =>
        operation?.availableStatuses.includes(object.status as PipeStatusEnum)
      )
      if (isNotValid) return true
    } else {
      return true
    }
  }
}