-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_channel.js
120 lines (107 loc) · 4.06 KB
/
action_channel.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
/*
* action_channel.js
*
* David Janes
* IOTDB.org
* 2016-09-24
*
* Copyright [2013-2016] [David P. Janes]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
"use strict";
const assert = require("assert");
const helpers = require("./helpers");
const iotdb_thing = require("..");
describe("action_channel", function() {
describe("action:change channel", function() {
const action = "change channel";
describe("thing:TV", function() {
const thing = "TV";
it("channel 32", function(done) {
const argument = 32
helpers.run({
action: action,
thing: thing,
argument: argument,
}, (error, matches) => {
try {
assert.ok(!error, "no error expected");
assert.deepEqual(helpers.response(matches), "HomeStar is changing channel to 32 for 1 TV");
assert.deepEqual(helpers.updates(matches).length, 1);
assert.deepEqual(helpers.select(matches, 'thing-main-tv').value.channel, "32");
done();
}
catch (x) {
done(x);
}
});
});
});
});
describe("action:switch channel", function() {
const action = "switch channel";
describe("thing:TV", function() {
const thing = "TV";
it("channel 48", function(done) {
const argument = 48
helpers.run({
action: action,
thing: thing,
argument: argument,
}, (error, matches) => {
try {
assert.ok(!error, "no error expected");
assert.deepEqual(helpers.response(matches), "HomeStar is changing channel to 48 for 1 TV");
assert.deepEqual(helpers.updates(matches).length, 1);
assert.deepEqual(helpers.select(matches, 'thing-main-tv').value.channel, "48");
done();
}
catch (x) {
done(x);
}
});
});
});
});
describe("action:set channel", function() {
const action = "set channel";
describe("thing:Radio", function() {
const thing = "Radio";
/*
* Note there's a bug in 'lib/match' - it should
* be matching two attibutes. So at some point this will break
* and the fix should be to add the other channel.
*/
it("channel 500 (becomes 535)", function(done) {
const argument = 500
helpers.run({
action: action,
thing: thing,
argument: argument,
}, (error, matches) => {
try {
assert.ok(!error, "no error expected");
assert.deepEqual(helpers.response(matches), "HomeStar is changing channel to 500 for 1 Radio");
assert.deepEqual(helpers.updates(matches).length, 1);
assert.deepEqual(helpers.select(matches, 'thing-main-radio').value.am, 535);
done();
}
catch (x) {
done(x);
}
});
});
});
});
});