# Using present and dig methods

Module: domain-module
Tags: spec pre-condition

# present

  • resent is a method in domain module inside pre/post conditions.
  • present checks if an optional field has a value.
Eg:
input(name:String?,age:Int)
pre{
  condition nameExists => present(input.name) -> employeeDomainLogic.checkName(input.name) failing "Name Doesnt Not exist"
                                                            
}

# dig

  • dig is a method present in domain module inside pre/post conditions.
  • dig method is used to get the value from a optional field.
Eg : 
  input(name:String?,age:Int)
  pre{
    condition nameExists => employeeDomainLogic.checkName(input.name.dig) failing "Name Doesnt Not exist"
}
  • As dig is performed on a optional field, dig on field with no value can throw a error, so use present before using a dig.
Eg : 
  input(name:String?,age:Int)
  pre{
    condition nameExists => present(input.name) -> employeeDomainLogic.checkName(input.name.dig) failing "Name Doesnt Not exist"
}