-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add response-preserve-whitespace-test.js
- Loading branch information
1 parent
fb24c7b
commit cac9c52
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict'; | ||
|
||
var request = require('request'); | ||
var assert = require('assert'); | ||
var http = require('http'); | ||
var soap = require('../'); | ||
var server; | ||
var port; | ||
|
||
describe('Preverse whitespace', function() { | ||
var wsdl = __dirname + '/wsdl/hello.wsdl'; | ||
var xml = require('fs').readFileSync(wsdl, 'utf8'); | ||
|
||
before(function(done) { | ||
server = http.createServer(function(req, res) { | ||
res.statusCode = 200; | ||
res.end('"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tns=\"http://www.examples.com/wsdl/HelloService.wsdl\"><soap:Body><tns:sayHelloResponse><tns:greeting> </tns:greeting></tns:sayHelloResponse></soap:Body></soap:Envelope>"'); | ||
}).listen(51515, done); | ||
}); | ||
|
||
after(function() { | ||
server.close(); | ||
}); | ||
|
||
it('removes leading and trailing whitespace by default', | ||
function(done) { | ||
var url = 'http://' + server.address().address + ':' + server.address().port; | ||
|
||
if (server.address().address === '0.0.0.0' || server.address().address === '::') { | ||
url = 'http://127.0.0.1:' + server.address().port; | ||
} | ||
|
||
soap.createClient( | ||
wsdl, | ||
{ | ||
endpoint: url | ||
}, | ||
function(err, client) { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
client.sayHello( | ||
{ | ||
firstName: ' hello world ' | ||
}, | ||
function(err, result, rawResponse, soapHeader, rawRequest) { | ||
if (err) { | ||
throw err; | ||
} | ||
assert.equal('', result.greeting); | ||
done(); | ||
} | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('preserves leading and trailing whitespace when preserveWhitespace option is true', | ||
function(done) { | ||
var url = 'http://' + server.address().address + ':' + server.address().port; | ||
|
||
if (server.address().address === '0.0.0.0' || server.address().address === '::') { | ||
url = 'http://127.0.0.1:' + server.address().port; | ||
} | ||
|
||
soap.createClient( | ||
wsdl, | ||
{ | ||
endpoint: url, | ||
preserveWhitespace: true | ||
}, | ||
function(err, client) { | ||
if (err) { | ||
console.log(err); | ||
throw err; | ||
} | ||
|
||
client.sayHello( | ||
{ | ||
firstName: 'hello world' | ||
}, | ||
function(err, result, rawResponse, soapHeader, rawRequest) { | ||
if (err) { | ||
console.log(err); | ||
throw err; | ||
} | ||
assert.equal(' ', result.greeting); | ||
done(); | ||
} | ||
); | ||
} | ||
); | ||
}); | ||
|
||
}); |