override using @OVERRIDES@ not working within .withHeaders (Details below) #253
mailtwogopal
started this conversation in
General
Replies: 1 comment 4 replies
-
Please don't worry about small letters between the CAPS for DATA template etc. as am using it right in my tests |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I have a situation that any of my test needs a token as one of the request headers, and we rely on a Soap call (REST version not available yet) to get that token. In PactumJS, I managed to call that soap WS with .withBody(XMLrequest) and from the xml response received, I converted it to json response using xml2js node library.
I was able to fetch the token from json response and using .returns stored that to a variable. When I try to override using @OVERRIDES@ inside .withHeaders like below, token value is set to undefined.
First call inside it block where am fetching token value from webservice1:
const fetchToken = await spec().withMethod('POST').withPath('url')
.withJson(reqbody).withHeaders({ "test": "test", "Content-Type": "application/json" }).expectStatus(200)
.returns((ctx) => {
var xmlResp = ctx.res.body;
convert.parseString(xmlResp, (err, jsonResp) => {
if (err) console.log(err)
tokenVal = jsonResp['test']['value'];
return tokenVal;
})
});
Second call inside it block where am trying to use the const fetchToken inside my 2nd test like below but tokenvalue in header is set to undefined.
await spec().withMethod('POST')
.withPath('url').withHeaders({
'@DaTa:TEMPLATE@': 'headers',
'@OVERRIDES@': {
'tokenvalue':
${fetchToken}
(also tried as simply as 'tokenvalue': fetchToken)}
})
.withJson({ '@DaTa:TEMPLATE@': 'reqpayload' }).inspect()
.expectStatus(200)
Can you check on this?
Beta Was this translation helpful? Give feedback.
All reactions