forked from node-red/node-red-web-nodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding TfL Underground query node and tests
- Loading branch information
Showing
6 changed files
with
510 additions
and
2 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
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,147 @@ | ||
<ArrayOfLineStatus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://webservices.lul.co.uk/"> | ||
<LineStatus ID="0" StatusDetails=""> | ||
<BranchDisruptions /> | ||
<Line ID="1" Name="Bakerloo" /> | ||
<Status ID="GS" CssClass="GoodService" Description="Good Service" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
<LineStatus ID="1" StatusDetails=""> | ||
<BranchDisruptions /> | ||
<Line ID="2" Name="Central" /> | ||
<Status ID="GS" CssClass="GoodService" Description="Good Service" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
<LineStatus ID="10" StatusDetails=""> | ||
<BranchDisruptions /> | ||
<Line ID="7" Name="Circle" /> | ||
<Status ID="GS" CssClass="GoodService" Description="Good Service" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
<LineStatus ID="2" | ||
StatusDetails="Minor delays between Barking and Upminster while we respond to a fire alert at Barking. GOOD SERVICE on the rest of the line."> | ||
<BranchDisruptions> | ||
<BranchDisruption> | ||
<StationTo ID="240" Name="Upminster" /> | ||
<StationFrom ID="14" Name="Barking" /> | ||
<Status ID="MD" CssClass="GoodService" Description="Minor Delays" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</BranchDisruption> | ||
</BranchDisruptions> | ||
<Line ID="9" Name="District" /> | ||
<Status ID="MD" CssClass="GoodService" Description="Minor Delays" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
<LineStatus ID="8" StatusDetails=""> | ||
<BranchDisruptions /> | ||
<Line ID="8" Name="Hammersmith and City" /> | ||
<Status ID="GS" CssClass="GoodService" Description="Good Service" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
<LineStatus ID="4" | ||
StatusDetails="Due to an obstruction on the track in the Westminster area. Valid tickets will be accepted on London Busses via any reasonable route. Customers should avoid the line where possible."> | ||
<BranchDisruptions /> | ||
<Line ID="4" Name="Jubilee" /> | ||
<Status ID="SD" CssClass="DisruptedService" Description="Severe Delays" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
<LineStatus ID="9" StatusDetails=""> | ||
<BranchDisruptions /> | ||
<Line ID="11" Name="Metropolitan" /> | ||
<Status ID="GS" CssClass="GoodService" Description="Good Service" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
<LineStatus ID="5" | ||
StatusDetails="Between Kennington and Camden Town via Bank only, due to a person ill on a train earlier at Angel. GOOD SERVICE on the rest of the line."> | ||
<BranchDisruptions /> | ||
<Line ID="5" Name="Northern" /> | ||
<Status ID="MS" CssClass="GoodService" Description="Minor Delays" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
<LineStatus ID="6" | ||
StatusDetails="No service Acton Town to Uxbridge. SEVERE DELAYS on the rest of the line while we fix a signal failure in the Acton Town area. Tickets will be accepted on London Buses and Great Northern via any reasonable route."> | ||
<BranchDisruptions> | ||
<BranchDisruption> | ||
<StationTo ID="244" Name="Uxbridge" /> | ||
<StationFrom ID="1" Name="Acton Town" /> | ||
<Status ID="PS" CssClass="DisruptedService" Description="Part Suspended" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</BranchDisruption> | ||
</BranchDisruptions> | ||
<Line ID="6" Name="Piccadilly" /> | ||
<Status ID="PS" CssClass="DisruptedService" Description="Part Suspended" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
<LineStatus ID="7" StatusDetails=""> | ||
<BranchDisruptions /> | ||
<Line ID="3" Name="Victoria" /> | ||
<Status ID="GS" CssClass="GoodService" Description="Good Service" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
<LineStatus ID="11" StatusDetails=""> | ||
<BranchDisruptions /> | ||
<Line ID="12" Name="Waterloo and City" /> | ||
<Status ID="GS" CssClass="GoodService" Description="Good Service" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
<LineStatus ID="82" | ||
StatusDetails="Severe delays between New Cross Gate and Crystal Palace / West Croydon only, due to a faulty National Rail train at Brockley. Tickets will be accepted on London Underground services via any reasonable route. GOOD SERVICE on all other routes."> | ||
<BranchDisruptions> | ||
<BranchDisruption> | ||
<StationTo ID="366" Name="West Croydon" /> | ||
<StationFrom ID="155" Name="New Cross Gate" /> | ||
<Status ID="SD" CssClass="DisruptedService" Description="Severe Delays" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</BranchDisruption> | ||
<BranchDisruption> | ||
<StationTo ID="305" Name="Crystal Palace" /> | ||
<StationFrom ID="155" Name="New Cross Gate" /> | ||
<Status ID="SD" CssClass="DisruptedService" Description="Severe Delays" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</BranchDisruption> | ||
</BranchDisruptions> | ||
<Line ID="82" Name="Overground" /> | ||
<Status ID="SD" CssClass="DisruptedService" Description="Severe Delays" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
<LineStatus ID="81" StatusDetails=""> | ||
<BranchDisruptions /> | ||
<Line ID="81" Name="DLR" /> | ||
<Status ID="GS" CssClass="GoodService" Description="Good Service" | ||
IsActive="true"> | ||
<StatusType ID="1" Description="Line" /> | ||
</Status> | ||
</LineStatus> | ||
</ArrayOfLineStatus> |
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,167 @@ | ||
/** | ||
* Copyright 2014 IBM Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
**/ | ||
|
||
var should = require("should"); | ||
var tubeNode = require("../../transport/tfl-underground.js"); | ||
var helper = require('../helper.js'); | ||
var sinon = require('sinon'); | ||
var path = require("path"); | ||
var fs = require('fs-extra'); | ||
var nock = helper.nock; | ||
|
||
describe('tfl-underground nodes', function() { | ||
|
||
var file = path.join(__dirname, "tfl-underground-response.xml"); | ||
|
||
before(function(done) { | ||
helper.startServer(done); | ||
}); | ||
|
||
beforeEach(function() { | ||
fs.existsSync(file).should.be.true; | ||
}); | ||
|
||
afterEach(function() { | ||
helper.unload(); | ||
}); | ||
|
||
describe('query node', function() { | ||
|
||
if (nock) { | ||
|
||
it(' can fetch Good Service information', function(done) { | ||
fs.readFile(file, 'utf8', function(err, data) { | ||
helper.load(tubeNode, | ||
[ {id:"n1", type:"helper", wires:[["n2"]]}, | ||
{id:"n2", type:"tfl underground", wires:[["n3"]], line:"Bakerloo", acceptedtcs:true}, | ||
{id:"n3", type:"helper"}], | ||
function() { | ||
var scope = nock('http://cloud.tfl.gov.uk').get('/TrackerNet/LineStatus').reply(200, data); | ||
|
||
var n1 = helper.getNode("n1"); | ||
var n2 = helper.getNode("n2"); | ||
var n3 = helper.getNode("n3"); | ||
n2.should.have.property('id','n2'); | ||
n1.send({payload:"foo"}); | ||
n3.on('input', function(msg){ | ||
msg.payload.should.have.property('status', "GoodService"); | ||
msg.payload.should.have.property('description', "Good Service"); | ||
msg.payload.should.have.property('details', ""); | ||
msg.payload.should.have.property('goodservice', true); | ||
msg.payload.should.have.property('branchdisruptions'); | ||
msg.payload.branchdisruptions.should.be.an.instanceOf(Array); | ||
msg.payload.branchdisruptions.length.should.equal(0); | ||
done(); | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
it(' can fetch Minor Delays information', function(done) { | ||
fs.readFile(file, 'utf8', function(err, data) { | ||
helper.load(tubeNode, | ||
[ {id:"n1", type:"helper", wires:[["n2"]]}, | ||
{id:"n2", type:"tfl underground", wires:[["n3"]], line:"District",acceptedtcs:true}, | ||
{id:"n3", type:"helper"}], | ||
function() { | ||
var scope = nock('http://cloud.tfl.gov.uk').get('/TrackerNet/LineStatus').reply(200, data); | ||
|
||
var n1 = helper.getNode("n1"); | ||
var n2 = helper.getNode("n2"); | ||
var n3 = helper.getNode("n3"); | ||
n2.should.have.property('id','n2'); | ||
n1.send({payload:"foo"}); | ||
n3.on('input', function(msg){ | ||
msg.payload.should.have.property('status', "GoodService"); | ||
msg.payload.should.have.property('description', "Minor Delays"); | ||
msg.payload.should.have.property('details'); | ||
msg.payload.details.should.equal("Minor delays between Barking and Upminster while we respond to a fire alert at Barking. GOOD SERVICE on the rest of the line."); | ||
msg.payload.should.have.property('goodservice', true); | ||
done(); | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
it(' can fetch Severe Delays information', function(done) { | ||
fs.readFile(file, 'utf8', function(err, data) { | ||
helper.load(tubeNode, | ||
[ {id:"n1", type:"helper", wires:[["n2"]]}, | ||
{id:"n2", type:"tfl underground", wires:[["n3"]], line:"Jubilee",acceptedtcs:true}, | ||
{id:"n3", type:"helper"}], | ||
function() { | ||
var scope = nock('http://cloud.tfl.gov.uk').get('/TrackerNet/LineStatus').reply(200, data); | ||
|
||
var n1 = helper.getNode("n1"); | ||
var n2 = helper.getNode("n2"); | ||
var n3 = helper.getNode("n3"); | ||
n2.should.have.property('id','n2'); | ||
n1.send({payload:"foo"}); | ||
n3.on('input', function(msg){ | ||
msg.payload.should.have.property('status', "DisruptedService"); | ||
msg.payload.should.have.property('description', "Severe Delays"); | ||
msg.payload.should.have.property('details'); | ||
msg.payload.details.should.equal("Due to an obstruction on the track in the Westminster area. Valid tickets will be accepted on London Busses via any reasonable route. Customers should avoid the line where possible."); | ||
msg.payload.should.have.property('goodservice', false); | ||
done(); | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
|
||
it(' can fetch branch disruption information', function(done) { | ||
fs.readFile(file, 'utf8', function(err, data) { | ||
helper.load(tubeNode, | ||
[ {id:"n1", type:"helper", wires:[["n2"]]}, | ||
{id:"n2", type:"tfl underground", wires:[["n3"]], line:"Piccadilly",acceptedtcs:true}, | ||
{id:"n3", type:"helper"}], | ||
function() { | ||
var scope = nock('http://cloud.tfl.gov.uk').get('/TrackerNet/LineStatus').reply(200, data); | ||
|
||
var n1 = helper.getNode("n1"); | ||
var n2 = helper.getNode("n2"); | ||
var n3 = helper.getNode("n3"); | ||
n2.should.have.property('id','n2'); | ||
n1.send({payload:"foo"}); | ||
n3.on('input', function(msg){ | ||
msg.payload.should.have.property('status', "DisruptedService"); | ||
msg.payload.should.have.property('description', "Part Suspended"); | ||
msg.payload.should.have.property('details'); | ||
msg.payload.details.should.equal("No service Acton Town to Uxbridge. SEVERE DELAYS on the rest of the line while we fix a signal failure in the Acton Town area. Tickets will be accepted on London Buses and Great Northern via any reasonable route."); | ||
msg.payload.should.have.property('goodservice', false); | ||
msg.payload.should.have.property('branchdisruptions'); | ||
msg.payload.branchdisruptions.should.be.an.instanceOf(Array); | ||
msg.payload.branchdisruptions.length.should.equal(1); | ||
var disruption = msg.payload.branchdisruptions[0]; | ||
disruption.StationFrom[0].$.Name.should.equal("Acton Town"); | ||
disruption.StationTo[0].$.Name.should.equal("Uxbridge"); | ||
disruption.Status[0].$.Description.should.equal("Part Suspended"); | ||
done(); | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
|
||
}} | ||
); | ||
|
||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.