Skip to content

Commit

Permalink
semi-working mocha test
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyskn committed May 11, 2012
1 parent 90305a6 commit 0ebed13
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 11 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"main": "index.js",
"scripts": {
"start": "node server.js",
"test": "node_modules/.bin/mocha test/*.js"
"test": "node_modules/.bin/mocha -R spec -u exports test/*.js"
},
"engines": {
"node": ">=0.6.0"
Expand All @@ -21,6 +21,7 @@
"devDependencies": {
"commander": "0.5.2",
"express" : "2.5.8",
"mocha" : "1.0.3"
"mocha" : "1.0.3",
"request" : "2.9.0"
}
}
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var config = require("commander"),

config
.option("-p, --port [port]", "Server port", 9876)
.option("-u, --soap-url [url]", "SOAP server url", "http://localhost:9000/merlin-server/services/")
.option("-u, --soap-url [url]", "SOAP server url", "http://localhost:15099/")
.option("-P, --prefix [prefix]", "Url prefix", "")
.parse(process.argv);

Expand Down
5 changes: 3 additions & 2 deletions src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ var resolveWsdl = function(soapServerUrl) {
var resolveService = function(req, res, next) {
var client = req._client;

var description = client.describe(),
availableMethods = description[req.params.service][req.params.service+"HttpPort"],
var description = client.describe();
console.log(JSON.stringify(description));
var availableMethods = description[req.params.service][req.params.service+"HttpPort"],
msg = "Unknown method: " + req.params.method + "\n"
+ "Use one of: _describe, " + Object.keys(availableMethods).join(", ");

Expand Down
77 changes: 77 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
var fs = require('fs'),
soap = require('soap'),
assert = require('assert'),
request = require('request'),
http = require('http');

var service = {
StockQuoteService: {
StockQuotePort: {
GetLastTradePrice: function(args) {
return { price: 19.56 };
}
}
}
}

var proxy;

module.exports = {
'Express SOAP Proxy Tests': {

'SOAP server should start': function(done) {
var wsdl = fs.readFileSync(__dirname+'/wsdl/stockquote.wsdl', 'utf8'),
server = http.createServer(function(req, res) {
res.statusCode = 404;
res.end();
});
server.listen(15099);
soap.listen(server, '/stockquote', service, wsdl);

request('http://localhost:15099', function(err, res, body) {
assert.ok(!err);
done();
})
},

'Proxy should start': function(done) {
proxy = require('../server');
request('http://localhost:9876', function(err, res, body) {
assert.ok(!err);
assert.equal(res.statusCode, 404);
done();
})
},

'Proxy should answer 400 when asked for inexistant WSDL': function(done) {
request('http://localhost:9876/_WSDL/_SERVICE', function(err, res, body) {
assert.ok(!err);
assert.equal(res.statusCode, 400);
assert.equal(body, "Unknown WSDL: _WSDL");
done();
})
},

'Proxy should answer 400 when asked for wrong service': function(done) {
request('http://localhost:9876/stockquote/_SERVICE', function(err, res, body) {
assert.ok(!err);
assert.equal(res.statusCode, 400);
console.log(body);
assert.ok(body.length);
done();
})
}

// 'Proxy should answer 400 when asked for service with wrong param names': function(done) {
// request('http://localhost:9876/stockquote/getLastTradePrice?PARAM=GOOG', function(err, res, body) {
// assert.ok(!err);
// console.log(res.statusCode);
// console.log(body);
// // assert.equal(res.statusCode, 400);
// // assert.ok(body.length);
// done();
// })
// }
}
}

21 changes: 15 additions & 6 deletions test/wsdl/StockQuote.wsdl → test/wsdl/stockquote.wsdl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@

<wsdl:types>
<xsd:schema targetNamespace="http://example.com/stockquote.xsd" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema">
<xsd:complexType name="ArrayOfTrade">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Trade" nillable="true" type="tns:Trade"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="Trade">
<xsd:restriction base="string">
<xsd:enumeration value="AAPL" />
<xsd:enumeration value="GOOG" />
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="TradePriceRequest">
<xsd:simpleType>
<xsd:restriction base="string">
<xsd:enumeration value="AAPL" />
<xsd:enumeration value="GOOG" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="tradeList" nillable="true" type="tns:ArrayOfTrade"/></xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="TradePrice">
<xsd:complexType>
Expand Down

0 comments on commit 0ebed13

Please sign in to comment.