-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
337 lines (323 loc) · 13.5 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
var assert = require("assert");
var DirecTV = require('./index.js');
// These tests require a Whole-Home DVR setup and for the main box to be turned on.
// Populate the following two variables with valid addresses:
var ipAddr = '192.168.1.102';
var clientAddr = '88F7C7DA0264';
var badipAddr1 = '192.168.abc.1';
var badipAddr2 = '192.168.100.100';
var badClientAddr = '1123123';
describe('DirecTV', function(){
describe('validateIP()', function(){
it('should return an error when given an invalid IPv4 address', function(done){
DirecTV.validateIP(badipAddr1, function(err) {
assert.equal('string', (typeof err.message));
done();
});
});
it('should return a timeout error upon request to non-existent server', function(done){
DirecTV.validateIP(badipAddr2, function(err) {
assert.equal('string', (typeof err.message));
done();
});
});
it('should not return an error when a valid Set Top Box is found', function(done){
DirecTV.validateIP(ipAddr, function(err) {
assert.equal(null, err);
done();
});
});
});
describe('Remote()', function(){
it('should return an object when given an IP address', function(){
assert.equal('object', (typeof new DirecTV.Remote(ipAddr)));
});
it('should throw an error when not given an IP address', function(){
var err;
try {
var Remote = new DirecTV.Remote();
} catch (e) {
err=e;
}
assert.equal('string', (typeof err.message));
});
});
});
describe('Remote', function(){
describe('getOptions()', function(){
it('should return an object', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getOptions(function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
});
describe('getLocations()', function(){
it('should return an object when not given a type', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getLocations(undefined, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an object when given type 0', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getLocations(0, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an object when given type 1', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getLocations(1, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an error when given an invalid type', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getLocations(2, function(err,response){
assert.equal('string', (typeof err.message));
done();
});
});
});
describe('getSerialNum()', function(){
it('should return an object when not given a clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getSerialNum(undefined, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an object when given a valid clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getSerialNum(clientAddr, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an error when given an invalid clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getSerialNum(badClientAddr, function(err,response){
assert.equal('string', (typeof err.message));
done();
});
});
});
describe('getVersion()', function(){
it('should return an object', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getVersion(function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
});
describe('getMode()', function(){
it('should return an object when not given a clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getMode(undefined, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an object when given a valid clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getMode(clientAddr, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an error when given an invalid clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getMode(badClientAddr, function(err,response){
assert.equal('string', (typeof err.message));
done();
});
});
});
describe('processKey()', function(){
it('should return an error when given an invalid key', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.processKey(undefined, undefined, function(err,response){
assert.equal('string', (typeof err.message));
done();
});
});
it('should return an object when given a valid key and no clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.processKey('guide', undefined, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an object when given a valid key and a valid clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.processKey('exit', clientAddr, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an error when given a valid key and an invalid clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.processKey('exit', badClientAddr, function(err,response){
assert.equal('string', (typeof err.message));
done();
});
});
});
describe('processCommand()', function() {
it('should return an error when given an invalid cmd', function (done) {
var Remote = new DirecTV.Remote(ipAddr);
Remote.processCommand(undefined, function (err, response) {
assert.equal('string', (typeof err.message));
done();
});
});
it('should return an object when given a valid cmd', function (done) {
var Remote = new DirecTV.Remote(ipAddr);
Remote.processCommand('FA91', function (err, response) {
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
});
describe('getProgInfo()', function() {
// in order to get a valid epoch timestamp for testing, we'll pull one out of a valid response
var startTime;
it('should return an error when given an invalid channel', function (done) {
var Remote = new DirecTV.Remote(ipAddr);
Remote.getProgInfo(undefined, undefined, undefined, function (err, response) {
assert.equal('string', (typeof err.message));
done();
});
});
it('should return an object when given a valid channel', function (done) {
var Remote = new DirecTV.Remote(ipAddr);
Remote.getProgInfo(296, undefined, undefined, function (err, response) {
if (err) throw err;
// parse the start time out so we can use it in the next tests
startTime=response.startTime + 3600;
assert.equal('object', (typeof response));
done();
});
});
it('should return an error when given a valid channel and an invalid startTime', function (done) {
var Remote = new DirecTV.Remote(ipAddr);
Remote.getProgInfo(296, 'garbageText', undefined, function (err, response) {
assert.equal('string', (typeof err.message));
done();
});
});
it('should return an object when given a valid channel and a valid startTime', function (done) {
var Remote = new DirecTV.Remote(ipAddr);
Remote.getProgInfo(296, startTime, undefined, function (err, response) {
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an error when given a valid channel, a valid startTime and an invalid clientAddr', function (done) {
var Remote = new DirecTV.Remote(ipAddr);
Remote.getProgInfo(296, startTime, badClientAddr, function (err, response) {
assert.equal('string', (typeof err.message));
done();
});
});
it('should return an object when given a valid channel, a valid startTime and a valid clientAddr', function (done) {
var Remote = new DirecTV.Remote(ipAddr);
Remote.getProgInfo(296, startTime, clientAddr, function (err, response) {
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
});
describe('getTuned()', function(){
it('should return an object when not given a clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getTuned(undefined, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an object when given a valid clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getTuned(clientAddr, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an error when given an invalid clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getTuned(badClientAddr, function(err,response){
assert.equal('string', (typeof err.message));
done();
});
});
});
// STILL NEED TO TEST THE tune() FUNCTION
describe('tune()', function(){
it('should return an error when not given a channel', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.tune(undefined, undefined, function(err,response){
assert.equal('string', (typeof err.message));
done();
});
});
it('should return an object when given a valid channel', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.tune(297, undefined, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an object when given a valid channel and a valid clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.tune(296, clientAddr, function(err,response){
if (err) throw err;
assert.equal('object', (typeof response));
done();
});
});
it('should return an error when given an invalid clientAddr', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.tune(297, badClientAddr, function(err,response){
assert.equal('string', (typeof err.message));
done();
});
});
});
});
describe('Miscellaneous', function(){
describe('Synchronous calls', function(){
// using getLocations() as an example of synchronous calls
it('should log output rather than return data', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getLocations(1);
setTimeout(done, 1000);
});
it('should log errors rather than return as well', function(done){
var Remote = new DirecTV.Remote(ipAddr);
Remote.getLocations('2');
setTimeout(done, 1000);
});
});
});