# Using present and dig methods
Module:
domain-module
Tags:
spec
pre-condition
# present
resentis a method indomain moduleinside pre/post conditions.presentchecks 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
digis a method present indomain moduleinside pre/post conditions.digmethod 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
digis performed on a optional field,digon field with no value can throw a error, so usepresentbefore using adig.
Eg :
input(name:String?,age:Int)
pre{
condition nameExists => present(input.name) -> employeeDomainLogic.checkName(input.name.dig) failing "Name Doesnt Not exist"
}