All files / modules/70-pipeline/utils inputSetUtils.ts

100% Statements 17/17
93.33% Branches 28/30
100% Functions 2/2
100% Lines 15/15

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              42x   42x                     42x 395x 5x   390x       81x   309x 80x   229x 9x   220x     42x 10x 10x    
/*
 * Copyright 2021 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import { cloneDeep, isNull, isUndefined, omitBy } from 'lodash-es'
import type { InputSetSummaryResponse } from 'services/pipeline-ng'
import { changeEmptyValuesToRunTimeInput } from './stageHelpers'
import type { InputSetDTO } from './types'
 
export interface InputSetSummaryResponseExtended extends InputSetSummaryResponse {
  outdated?: boolean // BE sends isOutdated in list view and outdated in Details view
  action?: string
  lastUpdatedBy?: string
  createdBy?: string
  inputFieldSummary?: string
}
 
export const isInputSetInvalid = (data: InputSetSummaryResponseExtended): boolean => {
  if (data.entityValidityDetails?.valid === false) {
    return true
  }
  if (
    data.inputSetErrorDetails?.uuidToErrorResponseMap &&
    Object.keys(data.inputSetErrorDetails.uuidToErrorResponseMap)?.length
  ) {
    return true
  }
  if (data.overlaySetErrorDetails && Object.keys(data.overlaySetErrorDetails)?.length) {
    return true
  }
  if (data.isOutdated || data.outdated) {
    return true
  }
  return false
}
 
export const clearNullUndefined = /* istanbul ignore next */ (data: InputSetDTO): InputSetDTO => {
  const omittedInputset = omitBy(omitBy(data, isUndefined), isNull)
  return changeEmptyValuesToRunTimeInput(cloneDeep(omittedInputset), '')
}