Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix regression errors for all test cases #11

Merged
merged 1 commit into from
Sep 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/parser/xmlHandler.js
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ class XMLHandler {
nsContext.popContext();
}
return node;
} else {
} else if (typeof val !== 'undefined' && typeof val != null) {
let attrs = val[this.options.attributesKey];
Copy link
Contributor

@raymondfeng raymondfeng Sep 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simpler test is val != null. Please note it is !=.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raymondfeng is val==null same as val!==null ??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I had a typo. Fixed now

if (typeof attrs === 'object') {
for (let p in attrs) {
@@ -161,7 +161,7 @@ class XMLHandler {
}
}

if (typeof val !== 'object' || (val instanceof Date)) {
if (typeof val !== 'undefined' && val !== null && ( typeof val !== 'object' || val instanceof Date)) {
// for adding a field value nsContext.popContext() shouldnt be called
element.text(val);
if (nameSpaceContextCreated) {
@@ -243,8 +243,13 @@ class XMLHandler {
let child = attrs[p];
// if field is $xsiType add xsi:type attribute
if (p === this.options.xsiTypeKey) {
// $xsiType has two fields - type, xmlns
let xsiType = QName.parse(child.type, child.xmlns);
let xsiType;
if(typeof child === 'object' && typeof child.type !== 'undefined') {
// $xsiType has two fields - type, xmlns
xsiType = QName.parse(child.type, child.xmlns);
} else {
xsiType = QName.parse(child);
}
declareNamespace(nsContext, node, 'xsi', helper.namespaces.xsi);
let mapping = declareNamespace(nsContext, node, xsiType.prefix,
xsiType.nsURI);
10 changes: 6 additions & 4 deletions test/client-test.js
Original file line number Diff line number Diff line change
@@ -268,7 +268,9 @@ describe('SOAP Client', function() {

//lastRequest should have proper header value of above JSON header object serialized based on header schema defined
//in default-namespace1.wsdl
var lastRequest = '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Header>\n <MyHeaderElem>\n <esnext>false</esnext>\n <moz>true</moz>\n <boss>true</boss>\n <node>true</node>\n <validthis>true</validthis>\n <globals>\n <EventEmitter>true</EventEmitter>\n <Promise>true</Promise>\n </globals>\n </MyHeaderElem>\n </soap:Header>\n <soap:Body/>\n</soap:Envelope>';
var lastRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Header>\n <ns1:MyHeaderElem xmlns:ns1=\"http://www.example.com/v1\">\n <ns1:esnext>false</ns1:esnext>\n"
+ " <ns1:moz>true</ns1:moz>\n <ns1:boss>true</ns1:boss>\n <ns1:node>true</ns1:node>\n <ns1:validthis>true</ns1:validthis>\n <ns1:globals>\n <ns1:EventEmitter>true</ns1:EventEmitter>\n <ns1:Promise>true</ns1:Promise>\n </ns1:globals>\n"
+ " </ns1:MyHeaderElem>\n </soap:Header>\n <soap:Body/>\n</soap:Envelope>";
client.MyOperation({}, function(err, result) {
//using lastRequest instead of lastRequestHeaders() since this doesn't contain soap header which this test case needs to test.
assert.equal(client.lastRequest, lastRequest);
@@ -442,13 +444,13 @@ describe('SOAP Client', function() {
var data = {
Request: {
$attributes: {
$xsiType: '{xmlnsTy}Ty'
$xsiType: "{xmlnsTy}Ty"
}
}
};

//In the new implementation the xsi:type results in the following format.
var message = '<soap:Body>\n <Request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="xmlnsTy" xsi:type="ns2:Ty"/>\n</soap:Body>\n';
var message = '<soap:Body>\n <ns1:Request xmlns:ns1=\"http://www.example.com/v1\" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="xmlnsTy" xsi:type="ns2:Ty"/>\n</soap:Body>\n';
client.MyOperation(data, function(err, result) {
assert.ok(client.lastRequest);
assert.ok(client.lastMessage);
@@ -464,7 +466,7 @@ describe('SOAP Client', function() {
}
};

var newMessage = '<soap:Body>\n <Request/>\n</soap:Body>\n';
var newMessage = '<soap:Body>\n <ns1:Request xmlns:ns1=\"http://www.example.com/v1\"/>\n</soap:Body>\n';
client.MyOperation(newData, function(err, result) {
assert.ok(client.lastRequest);
assert.ok(client.lastMessage);
5 changes: 3 additions & 2 deletions test/server-client-document-test.js
Original file line number Diff line number Diff line change
@@ -316,7 +316,8 @@ describe('Document style tests', function() {
client.myMethod({x: 200, y: 10.55}, function (err, result, body) {
assert.ok(err);
//check if fault exists with correct 'detail' parameters in the response
var index = body.indexOf('<myMethodFault1>');

var index = body.indexOf('myMethodFault1');
assert.ok(index > -1);
var index = body.indexOf('<errorMessage1>MyMethod Business Exception message</errorMessage1>');
assert.ok(index > -1);
@@ -437,7 +438,7 @@ describe('Document style tests', function() {
client.myMethod({x: 200, y: 10.55}, function (err, result, body) {
assert.ok(err);
//check if fault exists with correct 'detail' parameters in the response
var index = body.indexOf('<myMethodFault2>');
var index = body.indexOf('myMethodFault2');
assert.ok(index > -1);
var index = body.indexOf('<errorMessage2>MyMethod Business Exception message</errorMessage2>');
assert.ok(index > -1);
4 changes: 2 additions & 2 deletions test/server-options-test.js
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ describe('SOAP Server with Options', function() {


it('should return correct stock price in response body', function(done) {
var responseData = '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Header/>\n <soap:Body>\n <TradePrice>\n <price>19.56</price>\n </TradePrice>\n </soap:Body>\n</soap:Envelope>';
var responseData = '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Header/>\n <soap:Body>\n <ns1:TradePrice xmlns:ns1=\"http://example.com/stockquote.wsdl\">\n <price>19.56</price>\n </ns1:TradePrice>\n </soap:Body>\n</soap:Envelope>';
test.server.listen(15099, null, null, function() {
test.soapServer = soap.listen(test.server, {
path: '/stockquote',
@@ -190,7 +190,7 @@ describe('SOAP Server with Options', function() {
//skipping this test case since it's an invalid test case. The XML response sent for this test case from the server
//is invalid against stockthquote.wsdl. Added a new valid test case above 'should return correct stock price in response body'
it.skip('should escapeXML in response body', function(done) {
var responseData = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd"><soap:Body><xsd1:TradePrice xmlns:xsd1="http://example.com/stockquote.xsd">&lt;S:Envelope xmlns:S=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;&lt;S:Body&gt;&lt;ns3:UpdateProfileResponse xmlns:ns3=&quot;http://www.bigdatacollect.or/Name/Types&quot; xmlns=&quot;http://www.bigdatacollect.or/Common/Types&quot;&gt;&lt;ns3:Result resultStatusFlag=&quot;SUCCESS&quot;&gt;&lt;IDs&gt;&lt;UniqueID source=&quot;TESTSOURCE&quot;&gt;100&lt;/UniqueID&gt;&lt;/IDs&gt;&lt;/ns3:Result&gt;&lt;/ns3:UpdateProfileResponse&gt;&lt;/S:Body&gt;&lt;/S:Envelope&gt;</xsd1:TradePrice></soap:Body></soap:Envelope>';
var responseData = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:TradePrice xmlns:ns1=\"http://example.com/stockquote.xsd\">&lt;S:Envelope xmlns:S=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;&lt;S:Body&gt;&lt;ns3:UpdateProfileResponse xmlns:ns3=&quot;http://www.bigdatacollect.or/Name/Types&quot; xmlns=&quot;http://www.bigdatacollect.or/Common/Types&quot;&gt;&lt;ns3:Result resultStatusFlag=&quot;SUCCESS&quot;&gt;&lt;IDs&gt;&lt;UniqueID source=&quot;TESTSOURCE&quot;&gt;100&lt;/UniqueID&gt;&lt;/IDs&gt;&lt;/ns3:Result&gt;&lt;/ns3:UpdateProfileResponse&gt;&lt;/S:Body&gt;&lt;/S:Envelope&gt;</ns1:TradePrice></soap:Body></soap:Envelope>';
test.server.listen(15099, null, null, function() {
test.soapServer = soap.listen(test.server, {
path: '/stockquote',
2 changes: 1 addition & 1 deletion test/server-test.js
Original file line number Diff line number Diff line change
@@ -370,7 +370,7 @@ describe('SOAP Server', function() {
it('should return SOAP Fault body for SOAP 1.2', function(done) {
soap.createClient(test.baseUrl + '/stockquote?wsdl', function(err, client) {
assert.ok(!err);
var expectedBody = '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Header/>\n <soap:Body>\n <soap:Fault>\n <Code>\n <Value>soap:Sender</Value>\n <Subcode>\n <value>rpc:BadArguments</value>\n </Subcode>\n </Code>\n <Reason>\n <Text>Processing Error</Text>\n </Reason>\n </soap:Fault>\n </soap:Body>\n</soap:Envelope>';
var expectedBody = '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <soap:Header/>\n <soap:Body>\n <ns1:Fault>\n <Code>\n <Value>soap:Sender</Value>\n <Subcode>\n <value>rpc:BadArguments</value>\n </Subcode>\n </Code>\n <Reason>\n <Text>Processing Error</Text>\n </Reason>\n </ns1:Fault>\n </soap:Body>\n</soap:Envelope>';
client.GetLastTradePrice({ TradePriceRequest: {tickerSymbol: 'SOAP Fault v1.2' }}, function(err, response, body) {
assert.ok(err);
var fault = err.root.Envelope.Body.Fault;