ibm-messaging / mq-dev-patterns

Code samples and messaging patterns for IBM MQ developers
Apache License 2.0
191 stars 165 forks source link

Node test cases #232

Closed tanaysingh3484 closed 7 months ago

tanaysingh3484 commented 7 months ago

Created a test file for the basicget.js sample. Had to modify the package.json by adding the following devDependencies:

Also had to add a small modification in the basicget sample, so that the getMessage function could be tested. The following function :

function open(hConn, MQDetails) {
  return new Promise(function resolver(resolve, reject){
    debug_info('Opening MQ Connection');
    // Define what we want to open, and how we want to open it.
    let od = new mq.MQOD();
    od.ObjectName = MQDetails.QUEUE_NAME;
    od.ObjectType = MQC.MQOT_Q;
    let openOptions = MQC.MQOO_INPUT_AS_Q_DEF|MQC.MQOO_OUTPUT; 
    mq.Open(hConn, od, openOptions, function(err, hObj) {
      if (err) {
        debug_warn('Error Detected Opening MQ Connection', err);
        reject();
      } else {
        resolve(hObj);
      }
    });
  });
}

Had to modify the openOptions to have the MQC.MQOO_OUTPUT option, so that in the testing of the getMessage function, I could put a sample message into the queue, and check if the message is being successfully recieved. I was planning to comment it out in the original file, and add a comment stating that one should only uncomment the line when testing. Would like to know your insight on the following.