Forum Discussion

samuel_perez's avatar
samuel_perez
Occasional Contributor
8 years ago
Solved

ServiceV and assertions - need to refer to assertion text that fired

I have a  list of assertions defined on my VIRT for the list of required fields, i would like to send back a dynamic and accurate error message that indicates which field is missing , is there a way to refer to the assertion name that fired from the response? i release i could write a bunch of script to determine which fields were not present trying to see if the assertion name can be referred to as a property?

  • Hiya

     

    not sure how you've setup your assertions so don't know if there's a way of getting the info to return in a response message

     

    but rather than creating a bunch of code you could list the fields in a DS then iterate over the list and dynamically create and update a property appending any missing fields, this can then be easily referenced in a response if any are missing, one bit of code for all then rather than a bespoke 'bunch' of code

     

    create your list of missing fields then add to property

     

    set property

    context.mockService.setPropertyValue('failedParams',MISSINGFIELDS)

     

     

    use property within response

    {
        "Missing fields": "${#MockService#failedParams}"
    }

1 Reply

  • Hiya

     

    not sure how you've setup your assertions so don't know if there's a way of getting the info to return in a response message

     

    but rather than creating a bunch of code you could list the fields in a DS then iterate over the list and dynamically create and update a property appending any missing fields, this can then be easily referenced in a response if any are missing, one bit of code for all then rather than a bespoke 'bunch' of code

     

    create your list of missing fields then add to property

     

    set property

    context.mockService.setPropertyValue('failedParams',MISSINGFIELDS)

     

     

    use property within response

    {
        "Missing fields": "${#MockService#failedParams}"
    }