Added specs for Cylon#findRobotConnection

This commit is contained in:
Andrew Stewart 2014-03-09 19:06:06 -07:00
parent 691547a97f
commit a1b230c62d
2 changed files with 62 additions and 1 deletions

View File

@ -159,7 +159,7 @@ var Cylon = (function() {
var error,
connection = null;
if (err) { return callback(err, robot); }
if (err) { return callback ? callback(err, robot) : robot }
if (robot.connections[connid]) { connection = robot.connections[connid]; }

View File

@ -178,4 +178,65 @@ describe("Cylon", function() {
});
});
});
describe("#findRobotConnection", function() {
var bot, conn;
before(function() {
bot = cylon.robot({
name: "JARVIS",
connection: { name: "loopback", adaptor: "loopback" }
});
conn = bot.connections.loopback;
});
describe("async", function() {
context("looking for a valid robot/connection", function() {
it("calls the callback with the connection and no error message", function() {
var callback = spy();
cylon.findRobotConnection("JARVIS", "loopback", callback);
expect(callback).to.be.calledWith(undefined, conn);
});
});
context("looking for a valid robot and invalid connection", function() {
it("calls the callback with no connection and an error message", function() {
var callback = spy();
cylon.findRobotConnection("JARVIS", "nope", callback);
var error = { error: "No connection found with the name nope." };
expect(callback).to.be.calledWith(error, null);
});
});
context("looking for an invalid robot", function() {
it("calls the callback with no connection and an error message", function() {
var callback = spy();
cylon.findRobotConnection("Rob", "loopback", callback);
var error = { error: "No Robot found with the name Rob" };
expect(callback).to.be.calledWith(error, null);
});
});
});
describe("synchronous", function() {
context("looking for a valid robot/connection", function() {
it("returns the connection", function() {
expect(cylon.findRobotConnection("JARVIS", "loopback")).to.be.eql(conn);
});
});
context("looking for a valid robot and invalid connection", function() {
it("returns null", function() {
expect(cylon.findRobotConnection("JARVIS", "nope")).to.be.eql(null);
});
});
context("looking for an invalid robot", function() {
it("returns null", function() {
expect(cylon.findRobotConnection("Rob", "loopback")).to.be.eql(null);
});
});
});
});
});