From b124e243638746604b6b77c081eb0c4af35449fe Mon Sep 17 00:00:00 2001 From: Loren West Date: Mon, 29 Dec 2014 14:26:50 -0800 Subject: [PATCH 1/3] API command discovery and execution tests --- spec/lib/api/routes.spec.js | 112 ++++++++++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 6 deletions(-) diff --git a/spec/lib/api/routes.spec.js b/spec/lib/api/routes.spec.js index 87a5fef..641fb00 100644 --- a/spec/lib/api/routes.spec.js +++ b/spec/lib/api/routes.spec.js @@ -1,7 +1,25 @@ /* jshint expr:true */ "use strict"; -var router = source("api/routes"); +var Cylon = source("cylon"), + router = source("api/routes"); + +var MockRequest = require("../../support/mock_request"), + MockResponse = require("../../support/mock_response"); + +function findRoute(path) { + var routes = router.stack.filter(function(m) { + return m.regexp.test(path); + }); + return routes[0]; +} + +function findFinalHandler(path) { + var handlers = findRoute(path).route.stack.map(function(m) { + return m.handle; + }); + return handlers[handlers.length - 1]; +} describe("API routes", function() { var routes = [ @@ -25,11 +43,93 @@ describe("API routes", function() { path = route[1]; it("defines a " + method + " route for " + path, function() { - var matches = router.stack.map(function(m) { - return m.regexp.test(path); - }); - - expect(matches).to.include(true); + expect(findRoute(path)).to.exist(); }); }); + +}); + + +describe("API commands", function() { + + var req, res; + beforeEach(function() { + Cylon.commands.ping = function() { return "pong"; }; + req = new MockRequest(); + res = new MockResponse(); + req.device = { + name: "testDevice", + commands: { + announce: function(){return "im here";} + } + }; + req.robot = { + name: "fred", + commands: { + speak: function(){return "ahem";} + }, + devices: { + testDevice: req.device + } + }; + }); + afterEach(function() { + delete Cylon.commands.ping; + }); + + it("returns the list of MCP commands", function() { + res.json = function(obj){ + expect(obj.commands).to.exist(); + expect(obj.commands.length).to.equal(1); + expect(obj.commands[0]).to.equal("ping"); + }; + findFinalHandler("/commands")(req, res); + }); + + it("invokes an MCP command", function() { + req.params = {command:"ping"}; + res.json = function(obj){ + expect(obj.result).to.equal("pong"); + }; + findFinalHandler("/commands/ping")(req, res); + }); + + it("returns the list of robot commands", function() { + req.params = {robot: "fred"}; + res.json = function(obj){ + expect(obj.commands).to.exist(); + expect(obj.commands.length).to.equal(1); + expect(obj.commands[0]).to.equal("speak"); + }; + findFinalHandler("/robots/fred/commands")(req, res); + }); + + it("invokes a robot command", function() { + req.params = {robot: "fred", command:"speak"}; + res.json = function(obj){ + expect(obj.result).to.equal("ahem"); + }; + findFinalHandler("/robots/fred/commands/speak")(req, res); + }); + + it("returns the list of device commands", function() { + req.params = {robot: "fred", device: "testDevice" }; + res.json = function(obj){ + expect(obj.commands).to.exist(); + expect(obj.commands.length).to.equal(1); + expect(obj.commands[0]).to.equal("announce"); + }; + var path = "/robots/fred/devices/testDevice/commands"; + findFinalHandler(path)(req, res); + }); + + it("invokes a device command", function() { + req.params = {robot: "fred", device: "testDevice", command:"announce"}; + res.json = function(obj){ + expect(obj.result).to.equal("im here"); + }; + var path = "/robots/fred/devices/testDevice/commands/speak"; + findFinalHandler(path)(req, res); + }); + }); From 8d5aa817c1e03836f4001aed4280ab72a7bb91e2 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 30 Dec 2014 12:31:05 -0800 Subject: [PATCH 2/3] update robeaux screenshot --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 77d82c2..8536ca8 100644 --- a/README.markdown +++ b/README.markdown @@ -275,7 +275,7 @@ Cylon.api(); ``` Then visit `https://localhost:3000/` and you are ready to control your robots from a web browser! - + You can check out more information on the Cylon API in the docs [here](http://cylonjs.com/documentation/guides/api). From 0a4d91611ce95b165a4bd1fce942509b709a65a6 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 30 Dec 2014 12:53:55 -0800 Subject: [PATCH 3/3] update # of platforms --- README.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 8536ca8..b8940f5 100644 --- a/README.markdown +++ b/README.markdown @@ -189,7 +189,7 @@ Cylon.start(); ## Hardware Support Cylon.js has an extensible syntax for connecting to multiple, different hardware -devices. The following 32 platforms are currently supported: +devices. The following 34 platforms are currently supported: Platform | Support -------- | ------- @@ -202,11 +202,13 @@ Platform | Support [Bluetooth LE](http://en.wikipedia.org/wiki/Bluetooth_low_energy) | [cylon-ble](https://github.com/hybridgroup/cylon-ble) [Crazyflie](http://www.bitcraze.se/) | [cylon-crazyflie](https://github.com/hybridgroup/cylon-crazyflie) [Digispark](http://digistump.com/products/1) | [cylon-digispark](https://github.com/hybridgroup/cylon-digispark) +[Electric Imp](https://electricimp.com/product/) | [cylon-imp](https://github.com/hybridgroup/cylon-imp) [Intel Edison](http://www.intel.com/content/www/us/en/do-it-yourself/edison.html) | [cylon-intel-iot](https://github.com/hybridgroup/cylon-intel-iot) [Intel Galileo](http://www.intel.com/content/www/us/en/do-it-yourself/galileo-maker-quark-board.html) | [cylon-intel-iot](https://github.com/hybridgroup/cylon-intel-iot) [Joystick](http://en.wikipedia.org/wiki/Joystick) | [cylon-joystick](https://github.com/hybridgroup/cylon-joystick) [Keyboard](http://en.wikipedia.org/wiki/Computer_keyboard) | [cylon-keyboard](https://github.com/hybridgroup/cylon-keyboard) [Leap Motion](https://www.leapmotion.com/) | [cylon-leapmotion](https://github.com/hybridgroup/cylon-leapmotion) +[MiP](http://www.wowwee.com/mip/) | [cylon-mip](https://github.com/hybridgroup/cylon-mip) [MQTT](http://mqtt.org/) | [cylon-mqtt](https://github.com/hybridgroup/cylon-mqtt) [Nest](http://nest.com/) | [cylon-nest](https://github.com/hybridgroup/cylon-nest) [Neurosky](http://store.neurosky.com/products/mindwave-mobile) | [cylon-neurosky](https://github.com/hybridgroup/cylon-neurosky)