I am trying to run the following. I need the 1st call to set the environment variable for the second call.
console.log(“Create tender and flag Accepted”);
var interval = setTimeout(function() {}, 10000),
promiseMethod = function(text) {
var promise = new Promise(function(resolve, reject){
console.log('Enter: ’ + text);
setTimeout(function() {
console.log(‘Complete: ’ + text);
resolve({data: text + ’ 123’});
}, 2000);
});
return promise;
};
promiseMethod(‘first’)
.then((v) => {return promiseMethod(‘second’);})
.then((v) => {return promiseMethod(‘third’);})
.then((v) => {clearTimeout(interval);});
function first() {
var data = JSON.parse(pm.environment.get(‘data’));
data.TradingPartnerID = pm.environment.get('ediCustomerTradingPartnerKey');
data.SendDateTime = pm.environment.get('timestamp');
data.Header.Load.ShipmentID = "Test" + pm.environment.get('uniqueShipId');
data.Header.Load.Purpose_Qualifier = "00";
pm.environment.set("data", JSON.stringify(data));
const echoPostRequest = {
url: pm.environment.get('url') + '/edi/tender',
method: 'POST',
header: {
'Content-Type': 'application/json',
'Authorization': pm.environment.get('currentAccessTokenDev')
},
body: JSON.stringify(data)
};
pm.sendRequest(echoPostRequest, function(err, res) {
console.log('4. Ship ID Exist - Load tests');
pm.test('Creation of tender for test Shipment ID exists not canceled and load', function() {
pm.expect(err).to.equal(null);
pm.expect(res).to.have.property('code', 200);
pm.expect(res).to.have.property('status', 'OK');
});
pm.environment.set("tender_id", res.json().data.tender_id);
console.log("tender_id", res.json().data.tender_id);
});
}
function second() {
const acceptTender = {
url: pm.environment.get(‘url’) + ‘/edi/tender’ + pm.environment.get(‘tender_id’) + ‘/accept’,
method: ‘POST’,
header: {
‘Content-Type’: ‘application/json’,
‘Authorization’: pm.environment.get(‘currentAccessTokenDev’)
},
};
}