Skip to content

Commit

Permalink
Add bodyParser.json middleware test
Browse files Browse the repository at this point in the history
  • Loading branch information
amity0 authored and jsdevel committed Jan 24, 2019
1 parent e13942b commit 7a215e0
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/express-server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,58 @@ describe('Express server with middleware', function () {
});

});


describe('Express server with bodyParser.json middleware', function () {

before(function (done) {
var wsdl = '<definitions name="HelloService" targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><message name="SayHelloRequest"><part name="firstName" type="xsd:string"/></message><message name="SayHelloResponse"><part name="greeting" type="xsd:string"/></message><portType name="Hello_PortType"><operation name="sayHello"><input message="tns:SayHelloRequest"/><output message="tns:SayHelloResponse"/></operation></portType><binding name="Hello_Binding" type="tns:Hello_PortType"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="sayHello"><soap:operation soapAction="sayHello"/><input><soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:examples:helloservice" use="encoded"/></input><output><soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:examples:helloservice" use="encoded"/></output></operation></binding><service name="Hello_Service"><documentation>WSDL File for HelloService</documentation><port binding="tns:Hello_Binding" name="Hello_Port"><soap:address location="http://localhost:51515/SayHello/" /></port></service></definitions>';
var service = {
Hello_Service: {
Hello_Port: {
sayHello: function (args) {
return {
greeting: args.firstName
};
}
}
}
};
expressServer = express();
expressServer.use(bodyParser.json());

server = expressServer.listen(51515, function () {

var soapServer = soap.listen(expressServer, '/SayHello', service, wsdl);
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;
}

done();
});
});

after(function () {
server.close();
});

it('should not parse body on bodyParser.json middleware', function (done) {
request({
url: url + '/SayHello',
method: 'POST',
headers: {
SOAPAction: "sayHello",
"Content-Type": 'text/xml; charset="utf-8"'
},
body: requestXML
}, function (err, response, body) {
if (err) {
throw err;
}
assert.equal(body, responseXML);
done();
});
});
});

0 comments on commit 7a215e0

Please sign in to comment.