Updating tests¶
The example shown below is a test example when the user starts a session and asked to pick a route.
describe("when the user starts a session", function() {
it("should ask them to pick a route", function() {
return tester
.start()
.check.interaction({
state: 'states:start',
reply: [
'Welcome to CTA train tracker.Pick a route:',
'1. Red Line',
'2. Blue Line',
'3. Brown Line',
'4. Green Line',
'5. Orange Line',
'6. Purple Line',
'7. Pink Line',
'8. Exit'
].join('\n')
})
.run();
});
});
In the following example we want to check that the response was given to http://lapi.transitchicago.com/api/1.0/ttpositions.aspx?key=33305d8dcece4aa58c651c740f88d1e2&rt=red&outputType=JSON and check the the request’s data equals the content given by the user.
describe("when the user is asked to pick a route e.g red line", function() {
it("should select red line", function() {
return tester
.setup.user.state('states:red')
.input('1')
.check(function(api) {
var req = api.http.requests[0];
assert.deepEqual(req.params, {rt: 'red', key: '33305d8dcece4aa58c651c740f88d1e2', outputType: 'JSON'});
})
.run();
});
it("should tell them the result", function() {
return tester
.setup.user.state('states:start')
.input('1')
.check.interaction({
state: 'states:exit',
reply: [
"Thanks for using CTA tran tracker.",
"There are 2 trains on the red line."
].join(' ')
})
.check.reply.ends_session()
.run();
});
});
To run the tests type: npm test
Read more about Test Utilities here.