Browse files

Spelling fix and tests.

* 'metods' is spelled 'methods'.
* unit testing using mocha
  • Loading branch information...
1 parent 6ae6f7d commit d254ea3169116de92da149b4b630b7e4d94c684f @kmpm kmpm committed Sep 28, 2012
Showing with 57 additions and 9 deletions.
  1. +5 −1 package.json
  2. +3 −3 telldus.cc
  3. +0 −5 test.js
  4. +49 −0 test/telldus.test.js
View
6 package.json
@@ -13,4 +13,8 @@
, "main": "./telldus.js"
, "scripts": { "install": "node-waf configure build" }
, "os" : [ "darwin", "linux" ]
-}
+, "devDependencies": {
+ "mocha": "*"
+ , "should": "*"
+ }
+}
View
6 telldus.cc
@@ -43,7 +43,7 @@ namespace telldus_v8 {
return scope.Close(num);
}
- Local<Object> GetSuportedMetods(int id){
+ Local<Object> GetSuportedMethods(int id){
int methods = tdMethods( id, SUPPORTED_METHODS );
Local<Array> methodsObj = Array::New();
@@ -135,7 +135,7 @@ namespace telldus_v8 {
Local<Object> obj = Object::New();
obj->Set(String::NewSymbol("name"), String::New(name, strlen(name)));
obj->Set(String::NewSymbol("id"), Number::New(id));
- obj->Set(String::NewSymbol("metods"), GetSuportedMetods(id));
+ obj->Set(String::NewSymbol("methods"), GetSuportedMethods(id));
obj->Set(String::NewSymbol("model"), String::New(model, strlen(model)));
obj->Set(String::NewSymbol("type"), GetDeviceType(id));
obj->Set(String::NewSymbol("status"), GetDeviceStatus(id));
@@ -217,4 +217,4 @@ void init(Handle<Object> target) {
FunctionTemplate::New(telldus_v8::dim)->GetFunction());
}
-NODE_MODULE(telldus, init)
+NODE_MODULE(telldus, init)
View
5 test.js
@@ -1,5 +0,0 @@
-var telldus = require('./telldus');
-
-console.log(telldus.getDevices());
-console.log("blob");
- console.log(telldus.turnOn(1));
View
49 test/telldus.test.js
@@ -0,0 +1,49 @@
+
+var assert = require('assert')
+ , should = require('should');
+
+
+var telldus = require('../telldus');
+
+describe("telldus wrapper", function () {
+
+ /* for this test to work there must be a running
+ * telldusd and the first device must be a switch with
+ * TURNON,TURNOFF
+ */
+ it("list devices", function () {
+ var devices = telldus.getDevices();
+ //if devices is zero length then
+ //telldusd is probably not running
+ devices.length.should.be.within(1, 50);
+ var dev1 = devices[0];
+ dev1.should.have.property('name');
+ dev1.should.have.property('methods');
+ dev1.should.have.property('model');
+ dev1.should.have.property('type');
+ dev1.should.have.property('status');
+ //test status
+ dev1.status.should.have.property('name');
+
+ //test methods
+ var methods = dev1.methods;
+ methods.should.be.an.instanceOf(Array);
+ methods.should.include('TURNON');
+ methods.should.include('TURNOFF');
+ });
+
+ it('turnOff', function() {
+ var devices = telldus.getDevices();
+ telldus.turnOff(devices[0].id);
+ devices = telldus.getDevices();
+ devices[0].status.should.have.property('name', 'OFF');
+ });
+
+ it('turnOn', function() {
+ var devices = telldus.getDevices();
+ telldus.turnOn(devices[0].id);
+ devices = telldus.getDevices();
+ devices[0].status.should.have.property('name', 'ON');
+ });
+
+});

0 comments on commit d254ea3

Please sign in to comment.