|
| 1 | +varassert=require('assert'); |
| 2 | +varlogx=require("./logger")._system; |
| 3 | + |
| 4 | +varhomebridgeMock=require('./homebridge-mock')(); |
| 5 | + |
| 6 | +vardummyAuth={ |
| 7 | +client_id:"1234567890", |
| 8 | +client_secret:"0987654321", |
| 9 | +username:"test@tester.com", |
| 10 | +password:"password" |
| 11 | +}; |
| 12 | + |
| 13 | +varapi={ |
| 14 | +getStationsData:function(callback){ |
| 15 | +varstationData=[ |
| 16 | +{ |
| 17 | +"_id":"d1:00:00:00:00:00", |
| 18 | +"modules":[ |
| 19 | +{"_id":"d1:m1:11:11:11:11","data_type":[]}, |
| 20 | +], |
| 21 | +"data_type":[] |
| 22 | +},{ |
| 23 | +"_id":"d2:00:00:00:00:00", |
| 24 | +"modules":[ |
| 25 | +{"_id":"d2:m1:11:11:11:11","data_type":[]}, |
| 26 | +{"_id":"d2:m2:11:11:11:11","data_type":[]}, |
| 27 | +{"_id":"d2:m3:11:11:11:11","data_type":[]} |
| 28 | +], |
| 29 | +"data_type":[] |
| 30 | +},{ |
| 31 | +"_id":"d3:00:00:00:00:00", |
| 32 | +"modules":[ |
| 33 | +{"_id":"d3:m1:11:11:11:11","data_type":[]}, |
| 34 | +{"_id":"d3:m2:11:11:11:11","data_type":[]}, |
| 35 | +{"_id":"d3:m3:11:11:11:11","data_type":[]} |
| 36 | +], |
| 37 | +"data_type":[] |
| 38 | +} |
| 39 | +]; |
| 40 | +callback(null,stationData); |
| 41 | +}, |
| 42 | +getHomeData:function(callback){ |
| 43 | +varhomeData={"homes" : |
| 44 | +[ |
| 45 | +{"id" :"11:22:33:44:55:66"}, |
| 46 | +{"id" :"22:22:22:22:22:22"}, |
| 47 | +{"id" :"33:33:33:33:33:33"}, |
| 48 | +{"id" :"44:22:44:44:22:44"}, |
| 49 | +{"id" :"55:00:00:00:00:55"}, |
| 50 | +{"id" :"66:66:66:66:66:66"} |
| 51 | +] |
| 52 | +}; |
| 53 | +callback(null,homeData); |
| 54 | +} |
| 55 | +}; |
| 56 | + |
| 57 | +describe("Blacklist / Whitelist",function(){ |
| 58 | + |
| 59 | +describe("Weather Device",function(){ |
| 60 | + |
| 61 | +varWeatherDevice=require("../../device/weatherstation-device")(homebridgeMock); |
| 62 | + |
| 63 | +it('build accessories with empty config loads all',function(done){ |
| 64 | +varconfig={}; |
| 65 | +varstation=newWeatherDevice(logx,api,config); |
| 66 | + |
| 67 | +station.buildAccessoriesForDevices(function(err,deviceAccessories){ |
| 68 | +assert.equal(deviceAccessories.length,10); |
| 69 | +done(); |
| 70 | +}); |
| 71 | +}); |
| 72 | + |
| 73 | +it('build accessories with blacklist device loads all but module',function(done){ |
| 74 | +varconfig={blacklist:["d2:00:00:00:00:00"]}; |
| 75 | +varstation=newWeatherDevice(logx,api,config); |
| 76 | + |
| 77 | +station.buildAccessoriesForDevices(function(err,deviceAccessories){ |
| 78 | +assert.equal(deviceAccessories.length,9); |
| 79 | +done(); |
| 80 | +}); |
| 81 | +}); |
| 82 | + |
| 83 | +it('build accessories with blacklist module loads all but module',function(done){ |
| 84 | +varconfig={blacklist:["d2:m2:11:11:11:11"]}; |
| 85 | +varstation=newWeatherDevice(logx,api,config); |
| 86 | + |
| 87 | +station.buildAccessoriesForDevices(function(err,deviceAccessories){ |
| 88 | +assert.equal(deviceAccessories.length,9); |
| 89 | +done(); |
| 90 | +}); |
| 91 | +}); |
| 92 | + |
| 93 | +}); |
| 94 | + |
| 95 | +describe("Camera Device",function(){ |
| 96 | + |
| 97 | +varCameraDevice=require("../../device/camera-device")(homebridgeMock); |
| 98 | + |
| 99 | +it('build accessories with empty config loads all',function(done){ |
| 100 | +varconfig={}; |
| 101 | +varcamera=newCameraDevice(logx,api,config); |
| 102 | +camera.buildAccessoriesForDevices(function(err,deviceAccessories){ |
| 103 | +assert.equal(deviceAccessories.length,6); |
| 104 | +done(); |
| 105 | +}); |
| 106 | +}); |
| 107 | + |
| 108 | +it('build accessories with empty whitelist loads all',function(done){ |
| 109 | +varconfig={whitelist:[]}; |
| 110 | +varcamera=newCameraDevice(logx,api,config); |
| 111 | +camera.buildAccessoriesForDevices(function(err,deviceAccessories){ |
| 112 | +assert.equal(deviceAccessories.length,6); |
| 113 | +done(); |
| 114 | +}); |
| 115 | +}); |
| 116 | + |
| 117 | +it('build accessories with empty blacklist loads all',function(done){ |
| 118 | +varconfig={blacklist:[]}; |
| 119 | +varcamera=newCameraDevice(logx,api,config); |
| 120 | +camera.buildAccessoriesForDevices(function(err,deviceAccessories){ |
| 121 | +assert.equal(deviceAccessories.length,6); |
| 122 | +done(); |
| 123 | +}); |
| 124 | +}); |
| 125 | + |
| 126 | +it('build accessories with blacklist entry loads 5',function(done){ |
| 127 | +varconfig={blacklist:["33:33:33:33:33:33"]}; |
| 128 | +varcamera=newCameraDevice(logx,api,config); |
| 129 | +camera.buildAccessoriesForDevices(function(err,deviceAccessories){ |
| 130 | +assert.equal(deviceAccessories.length,5); |
| 131 | +// TODO: Check 333 not there! |
| 132 | +done(); |
| 133 | +}); |
| 134 | +}); |
| 135 | + |
| 136 | +it('build accessories with whitelist entry loads 1',function(done){ |
| 137 | +varconfig={whitelist:["55:00:00:00:00:55"]}; |
| 138 | +varcamera=newCameraDevice(logx,api,config); |
| 139 | +camera.buildAccessoriesForDevices(function(err,deviceAccessories){ |
| 140 | +assert.equal(deviceAccessories.length,1); |
| 141 | +// TODO: Check 333 not there! |
| 142 | +done(); |
| 143 | +}); |
| 144 | +}); |
| 145 | +}); |
| 146 | +}); |