Home > Mobile >  PactumJS Data:Template @OVERRIDE@ limited to top-level JSON
PactumJS Data:Template @OVERRIDE@ limited to top-level JSON

Time:11-07

Having a real problem with overriding a field in a data template. It works fine with top-level JSON fields, but second level or nested fields are out of scope.

I have a request body that looks like this:

{
    "method": "validateUserEmail",
    "parameters": {
        "email": "[email protected]"
    }
}

stash.addTemplate():

stash.addDataTemplate({
    'Generic1ParamRequestBody': {
        "method": "validateUserEmail",
        "parameters": {
            "email": ""
        }
    }
});

**call to OVERRIDE method field:** 

.withJson({
           '@DATA:TEMPLATE@': 'Generic1ParamRequestBody',
           '@OVERRIDES@': {
                'method': 'validateUserEmail' //WORKS
            },

**call to OVERRIDE email field: **

.withJson({
           '@DATA:TEMPLATE@': 'Generic1ParamRequestBody',
           '@OVERRIDES@': {
                'email': '[email protected]' //DOESNT WORK
            },

**All I get from the above is: **

"body": {
    "method": "validateUserEmail",
    "parameters": {
      "email": ""
    },
    "email": "[email protected]"
  },

Its like its not smart enough to look for email field on level 2 of nesting.

I've tried jsonpath (parameters.email) and changing the entire parameters field with JSON.stringify(parameters: { email: [email protected]}); But no luck at all.

Can anyone spot anything I am missing or doing daftly (instead of deftly)

CodePudding user response:

You are missing the parameters filed.

.withJson({
  '@DATA:TEMPLATE@': 'Generic1ParamRequestBody',
  '@OVERRIDES@': {
    'parameters': {
      "email": "abc"
    }
  }
})
  • Related