Skip to content

Commit

Permalink
Enable multiArgs during promisification
Browse files Browse the repository at this point in the history
Update documentation to reflect latest changes


Add whitespaces back


Implement promises tests
  • Loading branch information
rmobis authored and jsdevel committed Jan 16, 2018
1 parent d2039c2 commit 905eadb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,10 @@ Interesting properties might be:

``` javascript
client.MyFunctionAsync({name: 'value'}).then((result) => {
// result is a javascript array containing result, raw and soapheader
// result is a javascript object
// raw is the raw response
// soapHeader is the response soap header as a javascript object
})
```

Expand Down
7 changes: 5 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ var Client = function(wsdl, endpoint, options) {
this._initializeOptions(options);
this._initializeServices(endpoint);
this.httpClient = options.httpClient || new HttpClient(options);
var suffixOption = options.overridePromiseSuffix ? { suffix: options.overridePromiseSuffix } : null;
BluebirdPromise.promisifyAll(this, suffixOption);
var promiseOptions = { multiArgs: true };
if (options.overridePromiseSuffix) {
promiseOptions.suffix = options.overridePromiseSuffix;
}
BluebirdPromise.promisifyAll(this, promiseOptions);
};
util.inherits(Client, events.EventEmitter);

Expand Down
70 changes: 53 additions & 17 deletions test/request-response-samples-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,19 @@ tests.forEach(function(test){
else if(fs.existsSync(wsdlJSOptionsFile)) wsdlOptions = require(wsdlJSOptionsFile);
else wsdlOptions = {};

generateTest(name, methodName, wsdl, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, responseSoapHeaderJSON, wsdlOptions, options);
generateTest(name, methodName, wsdl, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, responseSoapHeaderJSON, wsdlOptions, options, false);
generateTest(name, methodName, wsdl, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, responseSoapHeaderJSON, wsdlOptions, options, true);
});

function generateTest(name, methodName, wsdlPath, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, responseSoapHeaderJSON, wsdlOptions, options){
function generateTest(name, methodName, wsdlPath, headerJSON, securityJSON, requestXML, requestJSON, responseXML, responseJSON, responseSoapHeaderJSON, wsdlOptions, options, usePromises){
var methodCaller = cbCaller;

if (usePromises) {
name += ' (promisified)';
methodName += 'Async';
methodCaller = promiseCaller;
}

suite[name] = function(done){
if(requestXML) requestContext.expectedRequest = requestXML;
if(responseXML) requestContext.responseToSend = responseXML;
Expand All @@ -143,25 +152,52 @@ function generateTest(name, methodName, wsdlPath, headerJSON, securityJSON, requ
throw new Error('method ' + methodName + ' does not exists in wsdl specified in test wsdl: ' + wsdlPath);
}

client[methodName](requestJSON, function(err, json, body, soapHeader){
if(requestJSON){
if (err) {
assert.notEqual('undefined: undefined', err.message);
assert.deepEqual(err.root, responseJSON);
} else {
// assert.deepEqual(json, responseJSON);
assert.equal(JSON.stringify(typeof json === 'undefined' ? null : json), JSON.stringify(responseJSON));
if(responseSoapHeaderJSON){
assert.equal(JSON.stringify(soapHeader), JSON.stringify(responseSoapHeaderJSON));
}
}
}
done();
}, options);
methodCaller(client, methodName, requestJSON, responseJSON, responseSoapHeaderJSON, options, done);
}, 'http://localhost:'+port+'/Message/Message.dll?Handler=Default');
};
}

function cbCaller(client, methodName, requestJSON, responseJSON, responseSoapHeaderJSON, options, done){
client[methodName](requestJSON, function(err, json, body, soapHeader){
if(requestJSON){
if (err) {
assert.notEqual('undefined: undefined', err.message);
assert.deepEqual(err.root, responseJSON);
} else {
// assert.deepEqual(json, responseJSON);
assert.equal(JSON.stringify(typeof json === 'undefined' ? null : json), JSON.stringify(responseJSON));
if(responseSoapHeaderJSON){
assert.equal(JSON.stringify(soapHeader), JSON.stringify(responseSoapHeaderJSON));
}
}
}
done();
}, options);
}

function promiseCaller(client, methodName, requestJSON, responseJSON, responseSoapHeaderJSON, options, done){
client[methodName](requestJSON).then(function(responseArr){
var json = responseArr[0];
var body = responseArr[1];
var soapHeader = responseArr[2];

if(requestJSON){
// assert.deepEqual(json, responseJSON);
assert.equal(JSON.stringify(typeof json === 'undefined' ? null : json), JSON.stringify(responseJSON));
if(responseSoapHeaderJSON){
assert.equal(JSON.stringify(soapHeader), JSON.stringify(responseSoapHeaderJSON));
}
}
}).catch(function(err) {
if(requestJSON){
assert.notEqual('undefined: undefined', err.message);
assert.deepEqual(err.root, responseJSON);
}
}).finally(function() {
done();
});
}

describe('Request Response Sampling', function() {
var origRandom = Math.random;

Expand Down

0 comments on commit 905eadb

Please sign in to comment.