Skip to content

Commit

Permalink
Remove unused coveralls, replace request with Axios in tests (#1250)
Browse files Browse the repository at this point in the history
  • Loading branch information
w666 authored Aug 20, 2024
1 parent f5b909c commit 08cecb5
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 985 deletions.
759 changes: 0 additions & 759 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"@types/whatwg-mimetype": "^3.0.2",
"body-parser": "^1.20.2",
"colors": "^1.4.0",
"coveralls": "^3.1.1",
"diff": "^5.2.0",
"doctoc": "^2.2.1",
"duplexer": "~0.1.2",
Expand Down
122 changes: 58 additions & 64 deletions test/express-server-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

var request = require('request');
var assert = require('assert');
var express = require('express');
var bodyParser = require('body-parser');
var soap = require('../');
const axios = require('axios');
var expressServer;
var server;
var port;
Expand Down Expand Up @@ -57,37 +57,36 @@ describe('Express server without middleware', function () {
});

it('should handle body without 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) {
axios.post(
url + '/SayHello',
requestXML,
{
headers: {
SOAPAction: "sayHello",
"Content-Type": 'text/xml; charset="utf-8"'
},
}).then(res => {
assert.equal(res.data, responseXML);
done();
}).catch(err => {
throw err;
}
assert.equal(body, responseXML);
done();
});
})
});

it('should serve wsdl', function (done) {
request({
url: url + '/SayHello?wsdl',
method: 'GET',
headers: {
"Content-Type": 'text/xml; charset="utf-8"'
axios.get(
url + '/SayHello?wsdl',
{
headers: {
"Content-Type": 'text/xml; charset="utf-8"'
}
}
}, function (err, response, body) {
if (err) {
).then(res => {
assert.equal(res.data, wsdl);
done();
}).catch(err => {
throw err;
}
assert.equal(body, wsdl);
done();
});
});
});

it('should handle other routes as usual', function (done) {
Expand All @@ -98,16 +97,13 @@ describe('Express server without middleware', function () {
return res.status(200).send('test passed');
});

request({
url: url + '/test/r1',
method: 'GET'
}, function (err, response, body) {
if (err) {
axios.get(
url + '/test/r1').then(res => {
assert.equal(res.data, 'test passed');
done();
}).catch(err => {
throw err;
}
assert.equal(body, 'test passed');
done();
});
});
});

});
Expand Down Expand Up @@ -148,21 +144,20 @@ describe('Express server with middleware', function () {
});

it('should allow parsing body via express 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();
});
axios.post(
url + '/SayHello',
requestXML,
{
headers: {
SOAPAction: "sayHello",
"Content-Type": 'text/xml; charset="utf-8"'
},
}).then(res => {
assert.equal(res.data, responseXML);
done();
}).catch(err => {
throw err
});
});

});
Expand Down Expand Up @@ -204,20 +199,19 @@ describe('Express server with bodyParser.json middleware', function () {
});

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) {
axios.post(
url + '/SayHello',
requestXML,
{
headers: {
SOAPAction: "sayHello",
"Content-Type": 'text/xml; charset="utf-8"'
},
}).then(res => {
assert.equal(res.data, responseXML);
done();
}).catch(err => {
throw err;
}
assert.equal(body, responseXML);
done();
});
});
});
});
43 changes: 22 additions & 21 deletions test/request-no-envelope-body-test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
'use strict';

var request = require('request');
var assert = require('assert');
var http = require('http');
var soap = require('../');
const { default: axios } = require('axios');
var server;
var port;

describe('No envelope and body elements', function() {
describe('No envelope and body elements', function () {
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>';
before(function(done){
server = http.createServer(function(req, res) {
before(function (done) {
server = http.createServer(function (req, res) {
res.statusCode = 404;
res.end();
}).listen(51515, function() {
}).listen(51515, function () {
var soapServer = soap.listen(server, '/SayHello', {
Hello_Service: {
Hello_Port: {
sayHello: function(args){
sayHello: function (args) {
return {
greeting: args.firstName
};
Expand All @@ -29,12 +29,12 @@ describe('No envelope and body elements', function() {
});
});

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

it('should throw an error when Body and Envelope are missing',
function(done){
function (done) {
var requestXML = '<sayHello xmlns="http://www.examples.com/wsdl/HelloService.wsdl"><firstName>tarun</firstName></sayHello>';
var url = 'http://' + server.address().address + ':' + server.address().port;

Expand All @@ -43,19 +43,20 @@ describe('No envelope and body elements', function() {
'http://127.0.0.1:' + server.address().port;
}

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.indexOf('Failed to parse the SOAP Message body') !== -1, true);
done();
});
axios.post(
url + '/SayHello',
requestXML,
{
headers: {
SOAPAction: "sayHello",
"Content-Type": 'text/xml; charset="utf-8"'
},
}).then(res => {
throw new Error(`Request must fail`);
}).catch(err => {
assert.equal(err?.response?.data.indexOf('Failed to parse the SOAP Message body') !== -1, true);
done();
});
});

});
1 change: 0 additions & 1 deletion test/response-preserve-whitespace-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var request = require('request');
var assert = require('assert');
var http = require('http');
var soap = require('../');
Expand Down
Loading

0 comments on commit 08cecb5

Please sign in to comment.