All files / libs/amalia-lang/formula/evaluate/shared/src/functions/misc/is-not-null index.ts

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

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 45 46 47 48 49 50 51 521x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { AmaliaFunctionCategory, AmaliaFunctionKeys, type AmaliaFormula } from '@amalia/amalia-lang/formula/types';
import { type ComputeEngineResult } from '@amalia/payout-calculation/types';
 
import { AmaliaFunctionDefault } from '../../AmaliaFunction';
 
export const miscIsNotNull = new AmaliaFunctionDefault<[ComputeEngineResult], boolean>({
  name: AmaliaFunctionKeys.isNotNull,
  category: AmaliaFunctionCategory.MISC,
 
  exec: (evaluate) => !(evaluate === null || evaluate === undefined || evaluate === Infinity || evaluate === -Infinity),
 
  // Do not put 1 here because execution will crash if null,
  // which is going against the purpose of this function.
  nbParamsRequired: 0,
  description: 'Check if parameter exists',
 
  params: [
    { name: 'parameter', description: 'Variables, Fields, Properties, Links etc. to check.', defaultValue: null },
  ],
 
  examples: [
    {
      desc: 'Returns true if cancelled date exists.',
      formula: 'isNotNull(opportunity.cancelledDate)' as AmaliaFormula,
    },
    {
      desc: 'Returns true since the parameter (0) is a defined value.',
      formula: 'isNotNull(0)' as AmaliaFormula,
      result: true,
    },
    {
      desc: 'Returns true if the link to previous opportunity exists.',
      formula: 'isNotNull(opportunity.previousOpportunity)' as AmaliaFormula,
    },
    {
      desc: 'Returns false since the parameter is null.',
      formula: 'isNotNull(null)' as AmaliaFormula,
      result: false,
    },
    {
      desc: 'Returns false since the parameter is undefined.',
      formula: 'isNotNull(undefined)' as AmaliaFormula,
      result: false,
    },
    {
      desc: 'Returns true since the parameter is defined.',
      formula: "isNotNull('test')" as AmaliaFormula,
      result: true,
    },
  ],
});