Skip to content

Commit

Permalink
add response-preserve-whitespace-test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
yffrankwang committed Apr 18, 2024
1 parent fb24c7b commit cac9c52
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions test/response-preserve-whitespace-test.js
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();
}
);
}
);
});

});

0 comments on commit cac9c52

Please sign in to comment.