homebridge-alexa 0.8.3-beta.1 → 0.8.3-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/package.json +1 -1
- package/src/lib/alexaActions.js +49 -36
- package/src/lib/alexaActions.test.js +205 -0
- package/src/lib/alexaLocal.js +2 -1
- package/src/lib/alexaLocal.test.js +78 -29
- package/src/lib/alexaActions.test.ts +0 -121
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/lib/alexaActions.js
CHANGED
|
@@ -4,6 +4,7 @@ var alexaMessages = require('./alexaMessages.js');
|
|
|
4
4
|
var messages = require('./parse/messages');
|
|
5
5
|
var debug = require('debug')('alexaActions');
|
|
6
6
|
var alexaLocal = require('./alexaLocal.js');
|
|
7
|
+
const process = require('process');
|
|
7
8
|
|
|
8
9
|
var homebridge;
|
|
9
10
|
var hbDevices;
|
|
@@ -102,7 +103,7 @@ function registerEvents(message) {
|
|
|
102
103
|
function alexaDiscovery(message, callback) {
|
|
103
104
|
// debug('alexaDiscovery', this);
|
|
104
105
|
homebridge.HAPaccessories(function (endPoints) {
|
|
105
|
-
debug("alexaDiscovery", this);
|
|
106
|
+
// debug("alexaDiscovery", this);
|
|
106
107
|
var response;
|
|
107
108
|
|
|
108
109
|
hbDevices = new Homebridges(endPoints, this);
|
|
@@ -380,12 +381,13 @@ function alexaPowerController(message, callback) {
|
|
|
380
381
|
}
|
|
381
382
|
|
|
382
383
|
function alexaModeController(message, callback) {
|
|
383
|
-
|
|
384
|
+
const action = message.directive.header.name;
|
|
385
|
+
var response;
|
|
384
386
|
try {
|
|
385
387
|
var haAction = JSON.parse(message.directive.endpoint.cookie[action]);
|
|
386
388
|
} catch (e) {
|
|
387
389
|
this.log("alexaModeController missing action", action, e.message, message.directive.endpoint.cookie);
|
|
388
|
-
|
|
390
|
+
response = alexaMessages.alexaResponse(message, "", e);
|
|
389
391
|
response.event.payload.type = "INVALID_VALUE"; // The directive contains a value that is not valid for the target endpoint. For example, an invalid heating mode, channel, or program value.
|
|
390
392
|
callback(e, response);
|
|
391
393
|
return;
|
|
@@ -401,7 +403,7 @@ function alexaModeController(message, callback) {
|
|
|
401
403
|
default:
|
|
402
404
|
this.log("alexaModeController missing mode", action, message.directive.payload.mode);
|
|
403
405
|
var e = new Error("alexaModeController missing mode " + action + " " + message.directive.payload);
|
|
404
|
-
|
|
406
|
+
response = alexaMessages.alexaResponse(message, "", e);
|
|
405
407
|
response.event.payload.type = "INVALID_VALUE"; // The directive contains a value that is not valid for the target endpoint. For example, an invalid heating mode, channel, or program value.
|
|
406
408
|
callback(e, response);
|
|
407
409
|
return;
|
|
@@ -427,12 +429,13 @@ function alexaModeController(message, callback) {
|
|
|
427
429
|
}
|
|
428
430
|
|
|
429
431
|
function alexaLockController(message, callback) {
|
|
430
|
-
|
|
432
|
+
const action = message.directive.header.name;
|
|
433
|
+
var response;
|
|
431
434
|
try {
|
|
432
435
|
var haAction = JSON.parse(message.directive.endpoint.cookie[action]);
|
|
433
436
|
} catch (e) {
|
|
434
437
|
this.log("alexaLockController missing action", action, e.message, message.directive.endpoint.cookie);
|
|
435
|
-
|
|
438
|
+
response = alexaMessages.alexaResponse(message, "", e);
|
|
436
439
|
response.event.payload.type = "INVALID_VALUE"; // The directive contains a value that is not valid for the target endpoint. For example, an invalid heating mode, channel, or program value.
|
|
437
440
|
callback(e, response);
|
|
438
441
|
return;
|
|
@@ -490,7 +493,7 @@ function alexaChannelController(message, callback) {
|
|
|
490
493
|
} else {
|
|
491
494
|
var e = new Error("ERROR: alexaChannelController missing channel", message.directive.endpoint.payload);
|
|
492
495
|
this.log(e.message);
|
|
493
|
-
|
|
496
|
+
response = alexaMessages.alexaResponse(message, "", e);
|
|
494
497
|
response.event.payload.type = "INVALID_DIRECTIVE"; // The directive contains a value that is not valid for the target endpoint. For example, an invalid heating mode, channel, or program value.
|
|
495
498
|
callback(e, response);
|
|
496
499
|
return;
|
|
@@ -499,7 +502,7 @@ function alexaChannelController(message, callback) {
|
|
|
499
502
|
var haAction = JSON.parse(message.directive.endpoint.cookie[channel.toUpperCase()]);
|
|
500
503
|
} catch (e) {
|
|
501
504
|
this.log("alexaChannelController invalid station", channel, e.message, message.directive.endpoint.cookie);
|
|
502
|
-
|
|
505
|
+
response = alexaMessages.alexaResponse(message, "", e);
|
|
503
506
|
response.event.payload.type = "VALUE_OUT_OF_RANGE"; // The directive contains a value that is not valid for the target endpoint. For example, an invalid heating mode, channel, or program value.
|
|
504
507
|
callback(e, response);
|
|
505
508
|
return;
|
|
@@ -517,11 +520,11 @@ function alexaChannelController(message, callback) {
|
|
|
517
520
|
|
|
518
521
|
homebridge.HAPcontrolByDeviceID(haAction.deviceID, JSON.stringify(body), function (err, status) {
|
|
519
522
|
if (err) {
|
|
520
|
-
this.log.error(message.directive.header.namespace,
|
|
523
|
+
this.log.error(message.directive.header.namespace, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""), (err ? "ERROR: " + err : ""));
|
|
521
524
|
} else if (status) {
|
|
522
|
-
this.log.warn(message.directive.header.namespace,
|
|
525
|
+
this.log.warn(message.directive.header.namespace, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
523
526
|
} else {
|
|
524
|
-
this.log(message.directive.header.namespace,
|
|
527
|
+
this.log(message.directive.header.namespace, haAction.deviceID, message.directive.endpoint.endpointId, (status ? status : ""));
|
|
525
528
|
}
|
|
526
529
|
var response = alexaMessages.alexaResponse(message, status, err);
|
|
527
530
|
callback(err, response);
|
|
@@ -530,14 +533,15 @@ function alexaChannelController(message, callback) {
|
|
|
530
533
|
|
|
531
534
|
async function alexaThermostatController(message, callback) {
|
|
532
535
|
// debug("alexaThermostatController", JSON.stringify(message));
|
|
533
|
-
|
|
534
|
-
|
|
536
|
+
const action = message.directive.header.name;
|
|
537
|
+
const payloads = message.directive.payload;
|
|
538
|
+
var haAction;
|
|
535
539
|
// directive.header.name = SetThermostatMode, SetTargetTemperature
|
|
536
540
|
switch (action) {
|
|
537
541
|
case "SetThermostatMode":
|
|
538
542
|
try {
|
|
539
543
|
var mode = message.directive.payload.thermostatMode.value;
|
|
540
|
-
|
|
544
|
+
haAction = JSON.parse(message.directive.endpoint.cookie["thermostatMode" + mode]);
|
|
541
545
|
} catch (e) {
|
|
542
546
|
this.log("alexaThermostatController missing action", "thermostatMode" + mode, e.message, message.directive.endpoint.cookie);
|
|
543
547
|
var response = alexaMessages.alexaResponse(message, "", e);
|
|
@@ -561,7 +565,6 @@ async function alexaThermostatController(message, callback) {
|
|
|
561
565
|
case "SetTargetTemperature":
|
|
562
566
|
// targetSetpoint, lowerSetpoint, upperSetpoint
|
|
563
567
|
var characteristics = [];
|
|
564
|
-
var haAction;
|
|
565
568
|
for (var index in payloads) {
|
|
566
569
|
try {
|
|
567
570
|
if (message.directive.endpoint.cookie[index]) {
|
|
@@ -1053,11 +1056,15 @@ async function processStatusArray(statusArray, message) {
|
|
|
1053
1056
|
// debug("processStatusArray", messageArray);
|
|
1054
1057
|
var resultArray = await Promise.all(messageArray);
|
|
1055
1058
|
|
|
1056
|
-
|
|
1057
|
-
|
|
1059
|
+
if (resultArray[0].length === 0) {
|
|
1060
|
+
throw new Error('No response from Homebridge')
|
|
1061
|
+
} else {
|
|
1062
|
+
return (alexaMessages.alexaStateResponse(resultArray, message));
|
|
1063
|
+
}
|
|
1058
1064
|
} catch (err) {
|
|
1065
|
+
debug("processStatusArray-Error", err);
|
|
1059
1066
|
if (this.deviceCleanup) {
|
|
1060
|
-
reportDeviceError(message);
|
|
1067
|
+
reportDeviceError.call(this, message);
|
|
1061
1068
|
}
|
|
1062
1069
|
return (alexaMessages.alexaStateResponse(err, message));
|
|
1063
1070
|
}
|
|
@@ -1122,27 +1129,33 @@ function alexaEvent(events) {
|
|
|
1122
1129
|
}
|
|
1123
1130
|
|
|
1124
1131
|
function reportDeviceError(message) {
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
"
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1132
|
+
// debug("reportDeviceError", message);
|
|
1133
|
+
this.log.error("Error: Device not responding, sending delete report", message.directive.endpoint.endpointId);
|
|
1134
|
+
try {
|
|
1135
|
+
alexaLocal.alexaEvent({
|
|
1136
|
+
"event": {
|
|
1137
|
+
"header": {
|
|
1138
|
+
"namespace": "Alexa.Discovery",
|
|
1139
|
+
"name": "DeleteReport",
|
|
1140
|
+
"messageId": messages.createMessageId(),
|
|
1141
|
+
"payloadVersion": "3"
|
|
1142
|
+
},
|
|
1143
|
+
"payload": {
|
|
1144
|
+
"endpoints": [
|
|
1145
|
+
{
|
|
1146
|
+
"endpointId": message.directive.endpoint.endpointId,
|
|
1147
|
+
}
|
|
1148
|
+
],
|
|
1149
|
+
"scope": {
|
|
1150
|
+
"type": "BearerToken",
|
|
1151
|
+
"token": "OAuth2.0 bearer token"
|
|
1137
1152
|
}
|
|
1138
|
-
],
|
|
1139
|
-
"scope": {
|
|
1140
|
-
"type": "BearerToken",
|
|
1141
|
-
"token": "OAuth2.0 bearer token"
|
|
1142
1153
|
}
|
|
1143
1154
|
}
|
|
1144
|
-
}
|
|
1145
|
-
})
|
|
1155
|
+
});
|
|
1156
|
+
} catch (e) {
|
|
1157
|
+
debug("reportDeviceError:", e);
|
|
1158
|
+
}
|
|
1146
1159
|
};
|
|
1147
1160
|
|
|
1148
1161
|
/*
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
const { alexaMessage, setHomebridge, destroy } = require('./alexaActions.js');
|
|
2
|
+
|
|
3
|
+
jest.mock("hap-node-client", () => {
|
|
4
|
+
// console.log('Mock - hap-node-client');
|
|
5
|
+
return { HAPNodeJSClient: jest.fn() };
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const HAPstatusByDeviceID = (deviceID, body, callback) => {
|
|
9
|
+
// console.log('Mock - HAPstatusByDeviceID', deviceID, body, callback);
|
|
10
|
+
switch (deviceID) {
|
|
11
|
+
case "ColorController-1":
|
|
12
|
+
callback(null, { deviceID: "device123", status: "on" });
|
|
13
|
+
break;
|
|
14
|
+
case "TemperatureSensor-Ok":
|
|
15
|
+
callback(null, { "characteristics": [{ "aid": 52, "iid": 12, "value": 2.5 }] });
|
|
16
|
+
break;
|
|
17
|
+
case "TemperatureSensor-NoData":
|
|
18
|
+
callback(null, { "characteristics": [{ "aid": 52, "iid": 12, "status": -70410 }] });
|
|
19
|
+
break;
|
|
20
|
+
default:
|
|
21
|
+
console.log('Missing Mock - HAPstatusByDeviceID', deviceID, body, callback);
|
|
22
|
+
callback(null, { deviceID: "device123", status: "off" });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
setHomebridge({
|
|
27
|
+
HAPstatusByDeviceID: HAPstatusByDeviceID,
|
|
28
|
+
destroy: jest.fn()
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('ReportState', () => {
|
|
32
|
+
|
|
33
|
+
const callback = jest.fn();
|
|
34
|
+
|
|
35
|
+
describe('deviceCleanup: false', () => {
|
|
36
|
+
const context = {
|
|
37
|
+
deviceCleanup: false,
|
|
38
|
+
log: jest.fn()
|
|
39
|
+
};
|
|
40
|
+
context.log.error = jest.fn();
|
|
41
|
+
|
|
42
|
+
beforeEach(() => {
|
|
43
|
+
callback.mockClear();
|
|
44
|
+
context.log.mockClear();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('ReportState - ColorController', async () => {
|
|
48
|
+
|
|
49
|
+
alexaMessage.call(context, message1, callback);
|
|
50
|
+
|
|
51
|
+
await sleep(500);
|
|
52
|
+
// Add your assertions here to verify the behavior of the function
|
|
53
|
+
expect(callback).toHaveBeenCalled();
|
|
54
|
+
// expect(callback.mock.calls[0][0].context.properties[0].value).toBe(2.5);
|
|
55
|
+
// ...
|
|
56
|
+
}, 5000);
|
|
57
|
+
|
|
58
|
+
test('ReportState - TemperatureSensor - Ok', async () => {
|
|
59
|
+
|
|
60
|
+
alexaMessage.call(context, message2, callback);
|
|
61
|
+
|
|
62
|
+
await sleep(500);
|
|
63
|
+
// Add your assertions here to verify the behavior of the function
|
|
64
|
+
// console.log(JSON.stringify(callback.mock.calls[0][1], null, 2));
|
|
65
|
+
expect(callback).toHaveBeenCalled();
|
|
66
|
+
const response = callback.mock.calls[0][1];
|
|
67
|
+
expect(response.context.properties[0].value.value).toBe(2.5);
|
|
68
|
+
expect(response.context.properties[0].value.scale).toBe("CELSIUS");
|
|
69
|
+
// ...
|
|
70
|
+
}, 5000);
|
|
71
|
+
|
|
72
|
+
test('ReportState - TemperatureSensor - No Data', async () => {
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
alexaMessage.call(context, message3, callback);
|
|
76
|
+
|
|
77
|
+
await sleep(500);
|
|
78
|
+
// Add your assertions here to verify the behavior of the function
|
|
79
|
+
// console.log(JSON.stringify(callback.mock.calls[0][1], null, 2));
|
|
80
|
+
expect(callback).toHaveBeenCalled();
|
|
81
|
+
const response = callback.mock.calls[0][1];
|
|
82
|
+
expect(response.event.header.name).toBe('ErrorResponse');
|
|
83
|
+
expect(response.event.payload.type).toBe('ENDPOINT_UNREACHABLE');
|
|
84
|
+
// ...
|
|
85
|
+
}, 5000);
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
test('should handle unknown directive', () => {
|
|
89
|
+
alexaMessage.call(context, message4, callback);
|
|
90
|
+
|
|
91
|
+
// Add your assertions here to verify the behavior of the function
|
|
92
|
+
expect(callback).toHaveBeenCalled();
|
|
93
|
+
// ...
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('deviceCleanup: true', () => {
|
|
98
|
+
var context = {
|
|
99
|
+
deviceCleanup: true,
|
|
100
|
+
log: jest.fn()
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
context.log.error = jest.fn();
|
|
104
|
+
|
|
105
|
+
beforeEach(() => {
|
|
106
|
+
callback.mockClear();
|
|
107
|
+
context.log.mockClear();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('ReportState - ColorController', async () => {
|
|
111
|
+
|
|
112
|
+
alexaMessage.call(context, message1, callback);
|
|
113
|
+
|
|
114
|
+
await sleep(500);
|
|
115
|
+
// Add your assertions here to verify the behavior of the function
|
|
116
|
+
expect(callback).toHaveBeenCalled();
|
|
117
|
+
// expect(callback.mock.calls[0][0].context.properties[0].value).toBe(2.5);
|
|
118
|
+
// ...
|
|
119
|
+
}, 5000);
|
|
120
|
+
|
|
121
|
+
test('ReportState - TemperatureSensor - Ok', async () => {
|
|
122
|
+
|
|
123
|
+
alexaMessage.call(context, message2, callback);
|
|
124
|
+
|
|
125
|
+
await sleep(500);
|
|
126
|
+
// Add your assertions here to verify the behavior of the function
|
|
127
|
+
// console.log(JSON.stringify(callback.mock.calls[0][1], null, 2));
|
|
128
|
+
expect(callback).toHaveBeenCalled();
|
|
129
|
+
const response = callback.mock.calls[0][1];
|
|
130
|
+
expect(response.context.properties[0].value.value).toBe(2.5);
|
|
131
|
+
expect(response.context.properties[0].value.scale).toBe("CELSIUS");
|
|
132
|
+
expect(context.log).toHaveBeenCalledTimes(0);
|
|
133
|
+
expect(context.log.error).toHaveBeenCalledTimes(0);
|
|
134
|
+
// ...
|
|
135
|
+
}, 5000);
|
|
136
|
+
|
|
137
|
+
test('ReportState - TemperatureSensor - No Data', async () => {
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
alexaMessage.call(context, message3, callback);
|
|
141
|
+
|
|
142
|
+
await sleep(500);
|
|
143
|
+
// Add your assertions here to verify the behavior of the function
|
|
144
|
+
// console.log(JSON.stringify(callback.mock.calls[0][1], null, 2));
|
|
145
|
+
expect(callback).toHaveBeenCalled();
|
|
146
|
+
expect(context.log).toHaveBeenCalledTimes(0);
|
|
147
|
+
expect(context.log.error).toHaveBeenCalledTimes(1);
|
|
148
|
+
expect(context.log.error).toHaveBeenCalledWith("Error: Device not responding, sending delete report", "Njk6NjI6Qjc6QUU6Mzg6RDQtRGVmYXVsdCBNb2RlbC1OUkNIS0IgLSBMYUNyb3NzZS1UWDE0MVctQmFja3lhcmQtMDAwMDAwOEEtMDAwMC0xMDAwLTgwMDAtMDAyNkJCNzY1Mjkx");
|
|
149
|
+
const response = callback.mock.calls[0][1];
|
|
150
|
+
expect(response.event.header.name).toBe('ErrorResponse');
|
|
151
|
+
expect(response.event.payload.type).toBe('ENDPOINT_UNREACHABLE');
|
|
152
|
+
// ...
|
|
153
|
+
}, 5000);
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
test('should handle unknown directive', () => {
|
|
157
|
+
alexaMessage.call(context, message4, callback);
|
|
158
|
+
|
|
159
|
+
// Add your assertions here to verify the behavior of the function
|
|
160
|
+
expect(callback).toHaveBeenCalled();
|
|
161
|
+
// ...
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
afterAll(() => {
|
|
168
|
+
destroy();
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
async function sleep(ms) {
|
|
173
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
const message1 = {
|
|
178
|
+
directive: {
|
|
179
|
+
header: {
|
|
180
|
+
name: 'ReportState'
|
|
181
|
+
},
|
|
182
|
+
endpoint: {
|
|
183
|
+
cookie: {
|
|
184
|
+
ReportState: '[{"deviceID": "ColorController-1", "interface": "Alexa.ColorController", "hue": {"aid": "1", "iid": "1"}, "saturation": {"aid": "1", "iid": "2"}, "brightness": {"aid": "1", "iid": "3"}}]'
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const message2 = { "directive": { "header": { "namespace": "Alexa", "name": "ReportState", "payloadVersion": "3", "messageId": "1cb7b217-3c2d-40e3-ab3d-fb66fb8bca2f", "correlationToken": "AAAAAAAAAAD9h7NYdun8GkFXkq4RJRZvAAIAAAAAAADHILDp6OTWHFoOX24pkmhvbtYnQ8g2cZAZwwHKZaR7/SF/tatX8I5tEBULWfoqY9WqeLu/WmF2n2mq4RFpbVg6yRZMPdeRbllXqMsG+tSGiiVmdyYT7BP32HlAELpOwtSXbnxNqGomxV7dqfZO2HYAj6qXSLUbnXYmSO7pDiMqT/PUbPSO+1MhcjYSF1UGV11JFihHGNuUyd0VN/bUoW46YWbxzB/zYPk+RUqA1uOfUzVWso8NuDNsE2BWFe4xO1thtJCOQjS9Wo5VA0avOeLO48aMNQ4Awby4aJWW+WzT+qp3v5xqQMwa3m0r8b89CTT2L4LcSD+A5JGE5nwppZyXjFeqgX5W1bY41z6cwjL6U+nW9xhQUzMXDDZ0/nD6bw77+oYQBkes2eexQbUgcl3cjw5OrmdbseOcyo4THzNRfuhZbebMQ/jTEameb/GnFWHoXdmpmR8Md5sEaDXv3X6Qfi2oCw7OXzuCBTHngGf82xw6wQd6ETymES0mZdsvwHTL3HUQBhR6xrAcg4MBPYuGSgVSiAAtresmexfxCDvYIcFf1o6c78w+o3c+w4Cprg6sU+OeF16ouuAjhs3qbX+sgmV9W9tWBPGirQA1WXvePz3LP8SPyjj0BAQ9nnr0tJ59jMtSaRwu6FFnwheVSAyZihggIVTD1pQ+nusFrJkahA==" }, "endpoint": { "endpointId": "Njk6NjI6Qjc6QUU6Mzg6RDQtRGVmYXVsdCBNb2RlbC1OUkNIS0IgLSBMYUNyb3NzZS1UWDE0MVctQmFja3lhcmQtMDAwMDAwOEEtMDAwMC0xMDAwLTgwMDAtMDAyNkJCNzY1Mjkx", "cookie": { "ReportState": "[{\"interface\":\"Alexa.TemperatureSensor\",\"deviceID\":\"TemperatureSensor-Ok\",\"aid\":52,\"iid\":12}]" } }, "payload": {} } };
|
|
191
|
+
|
|
192
|
+
const message3 = { "directive": { "header": { "namespace": "Alexa", "name": "ReportState", "payloadVersion": "3", "messageId": "1cb7b217-3c2d-40e3-ab3d-fb66fb8bca2f", "correlationToken": "AAAAAAAAAAD9h7NYdun8GkFXkq4RJRZvAAIAAAAAAADHILDp6OTWHFoOX24pkmhvbtYnQ8g2cZAZwwHKZaR7/SF/tatX8I5tEBULWfoqY9WqeLu/WmF2n2mq4RFpbVg6yRZMPdeRbllXqMsG+tSGiiVmdyYT7BP32HlAELpOwtSXbnxNqGomxV7dqfZO2HYAj6qXSLUbnXYmSO7pDiMqT/PUbPSO+1MhcjYSF1UGV11JFihHGNuUyd0VN/bUoW46YWbxzB/zYPk+RUqA1uOfUzVWso8NuDNsE2BWFe4xO1thtJCOQjS9Wo5VA0avOeLO48aMNQ4Awby4aJWW+WzT+qp3v5xqQMwa3m0r8b89CTT2L4LcSD+A5JGE5nwppZyXjFeqgX5W1bY41z6cwjL6U+nW9xhQUzMXDDZ0/nD6bw77+oYQBkes2eexQbUgcl3cjw5OrmdbseOcyo4THzNRfuhZbebMQ/jTEameb/GnFWHoXdmpmR8Md5sEaDXv3X6Qfi2oCw7OXzuCBTHngGf82xw6wQd6ETymES0mZdsvwHTL3HUQBhR6xrAcg4MBPYuGSgVSiAAtresmexfxCDvYIcFf1o6c78w+o3c+w4Cprg6sU+OeF16ouuAjhs3qbX+sgmV9W9tWBPGirQA1WXvePz3LP8SPyjj0BAQ9nnr0tJ59jMtSaRwu6FFnwheVSAyZihggIVTD1pQ+nusFrJkahA==" }, "endpoint": { "endpointId": "Njk6NjI6Qjc6QUU6Mzg6RDQtRGVmYXVsdCBNb2RlbC1OUkNIS0IgLSBMYUNyb3NzZS1UWDE0MVctQmFja3lhcmQtMDAwMDAwOEEtMDAwMC0xMDAwLTgwMDAtMDAyNkJCNzY1Mjkx", "cookie": { "ReportState": "[{\"interface\":\"Alexa.TemperatureSensor\",\"deviceID\":\"TemperatureSensor-NoData\",\"aid\":52,\"iid\":12}]" } }, "payload": {} } };
|
|
193
|
+
|
|
194
|
+
const message4 = {
|
|
195
|
+
directive: {
|
|
196
|
+
header: {
|
|
197
|
+
name: 'Unknown'
|
|
198
|
+
},
|
|
199
|
+
endpoint: {
|
|
200
|
+
cookie: {
|
|
201
|
+
reportstate: '[{"deviceID": "1", "interface": "Alexa.ColorController", "hue": {"aid": "1", "iid": "1"}, "saturation": {"aid": "1", "iid": "2"}, "brightness": {"aid": "1", "iid": "3"}}]'
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
package/src/lib/alexaLocal.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const process = require('process');
|
|
3
4
|
const mqtt = require('mqtt');
|
|
4
5
|
const debug = require('debug')('alexaLocal');
|
|
5
6
|
const Bottleneck = require('bottleneck');
|
|
@@ -18,7 +19,7 @@ let Characteristic;
|
|
|
18
19
|
module.exports = {
|
|
19
20
|
alexaLocal,
|
|
20
21
|
alexaEvent,
|
|
21
|
-
alexaPriorityEvent
|
|
22
|
+
alexaPriorityEvent
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
function alexaLocal(options) {
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
const mqtt = require('mqtt');
|
|
2
|
-
const debug = require('debug');
|
|
3
2
|
const Bottleneck = require('bottleneck');
|
|
4
|
-
const { alexaLocal, alexaEvent, alexaPriorityEvent } = require('
|
|
3
|
+
const { alexaLocal, alexaEvent, alexaPriorityEvent } = require('./alexaLocal');
|
|
5
4
|
|
|
6
5
|
jest.mock('mqtt');
|
|
7
|
-
jest.mock('debug');
|
|
8
6
|
jest.mock('bottleneck');
|
|
9
7
|
|
|
10
|
-
describe
|
|
8
|
+
describe('alexaLocal', () => {
|
|
11
9
|
let options;
|
|
12
10
|
let mockClient;
|
|
13
11
|
let mockLimiter;
|
|
@@ -32,6 +30,8 @@ describe.skip('alexaLocal', () => {
|
|
|
32
30
|
log: jest.fn()
|
|
33
31
|
};
|
|
34
32
|
|
|
33
|
+
options.log.error = jest.fn();
|
|
34
|
+
|
|
35
35
|
mockClient = {
|
|
36
36
|
on: jest.fn(),
|
|
37
37
|
publish: jest.fn(),
|
|
@@ -110,7 +110,7 @@ describe.skip('alexaLocal', () => {
|
|
|
110
110
|
options.Characteristic.ContactSensorState,
|
|
111
111
|
options.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
|
|
112
112
|
);
|
|
113
|
-
expect(options.log.error).toHaveBeenCalledWith(expect.stringContaining('Login
|
|
113
|
+
expect(options.log.error).toHaveBeenCalledWith(expect.stringContaining('ERROR: (homebridge-alexa) Login failed. Validate credentials in config.json.'));
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
test('should publish alexaEvent', () => {
|
|
@@ -131,30 +131,79 @@ describe.skip('alexaLocal', () => {
|
|
|
131
131
|
expect(mockLimiter.submit).toHaveBeenCalledWith({ priority: 4 }, expect.any(Function));
|
|
132
132
|
});
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
134
|
+
describe('MQTT Message Handler', () => {
|
|
135
|
+
test("Without Response - should generate alexaErrorResponse", async () => {
|
|
136
|
+
alexaLocal(options);
|
|
137
|
+
const connectHandler = mockClient.on.mock.calls[0][1];
|
|
138
|
+
connectHandler();
|
|
139
|
+
mockClient.publish.mockClear();
|
|
140
|
+
// await sleep(10000);
|
|
141
|
+
// Find the message handler from mockClient.on calls
|
|
142
|
+
const messageHandler = mockClient.on.mock.calls.find(
|
|
143
|
+
(call) => call[0] === "message"
|
|
144
|
+
)[1];
|
|
145
|
+
|
|
146
|
+
// Simulate an incoming MQTT message
|
|
147
|
+
const topic = "command/testUser/1";
|
|
148
|
+
const payload = JSON.stringify(message1);
|
|
149
|
+
|
|
150
|
+
messageHandler(topic, payload);
|
|
151
|
+
|
|
152
|
+
// Verify eventBus.emit was called with the received message
|
|
153
|
+
expect(options.eventBus.emit).toHaveBeenCalledWith("Alexa", message1, expect.any(Function));
|
|
154
|
+
|
|
155
|
+
const emitCallback = options.eventBus.emit.mock.calls.find(
|
|
156
|
+
(call) => call[0] === "Alexa"
|
|
157
|
+
)[2];
|
|
158
|
+
|
|
159
|
+
expect(emitCallback).toBeInstanceOf(Function); // Ensure it's a function
|
|
160
|
+
|
|
161
|
+
// Call the captured callback
|
|
162
|
+
emitCallback();
|
|
163
|
+
|
|
164
|
+
expect(mockClient.publish).toHaveBeenCalledWith("response/testUser/1", "{\"event\":{\"header\":{\"name\":\"ErrorResponse\",\"namespace\":\"Alexa\",\"payloadVersion\":\"3\",\"messageId\":\"1cb7b217-3c2d-40e3-ab3d-fb66fb8bca2f\"},\"payload\":{\"type\":\"INVALID_DIRECTIVE\",\"message\":\"No listener for directive\"}}}");
|
|
165
|
+
expect(options.log.error).toHaveBeenCalledWith("ERROR Response", JSON.stringify(message1));
|
|
166
|
+
expect(options.log.error).toHaveBeenCalledTimes(1);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("With Response", async () => {
|
|
170
|
+
alexaLocal(options);
|
|
171
|
+
const connectHandler = mockClient.on.mock.calls[0][1];
|
|
172
|
+
connectHandler();
|
|
173
|
+
mockClient.publish.mockClear();
|
|
174
|
+
// await sleep(10000);
|
|
175
|
+
// Find the message handler from mockClient.on calls
|
|
176
|
+
const messageHandler = mockClient.on.mock.calls.find(
|
|
177
|
+
(call) => call[0] === "message"
|
|
178
|
+
)[1];
|
|
179
|
+
|
|
180
|
+
// Simulate an incoming MQTT message
|
|
181
|
+
const topic = "command/testUser/1";
|
|
182
|
+
const payload = JSON.stringify(message1);
|
|
183
|
+
|
|
184
|
+
messageHandler(topic, payload);
|
|
185
|
+
|
|
186
|
+
// Verify eventBus.emit was called with the received message
|
|
187
|
+
expect(options.eventBus.emit).toHaveBeenCalledWith("Alexa", message1, expect.any(Function));
|
|
188
|
+
|
|
189
|
+
const emitCallback = options.eventBus.emit.mock.calls.find(
|
|
190
|
+
(call) => call[0] === "Alexa"
|
|
191
|
+
)[2];
|
|
192
|
+
|
|
193
|
+
expect(emitCallback).toBeInstanceOf(Function); // Ensure it's a function
|
|
194
|
+
|
|
195
|
+
// Call the captured callback
|
|
196
|
+
emitCallback(null, message1);
|
|
197
|
+
|
|
198
|
+
expect(mockClient.publish).toHaveBeenCalledWith('response/testUser/1', JSON.stringify(message1));
|
|
199
|
+
expect(options.log.error).toHaveBeenCalledTimes(0);
|
|
142
200
|
|
|
143
|
-
const response = _alexaErrorResponse(message);
|
|
144
|
-
|
|
145
|
-
expect(response).toEqual({
|
|
146
|
-
event: {
|
|
147
|
-
header: {
|
|
148
|
-
name: 'ErrorResponse',
|
|
149
|
-
namespace: 'Alexa',
|
|
150
|
-
payloadVersion: '3',
|
|
151
|
-
messageId: 'testMessageId'
|
|
152
|
-
},
|
|
153
|
-
payload: {
|
|
154
|
-
type: 'INVALID_DIRECTIVE',
|
|
155
|
-
message: 'No listener for directive'
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
201
|
});
|
|
159
202
|
});
|
|
160
|
-
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const message1 = { "directive": { "header": { "namespace": "Alexa", "name": "ReportState", "payloadVersion": "3", "messageId": "1cb7b217-3c2d-40e3-ab3d-fb66fb8bca2f", "correlationToken": "AAAAAAAAAAD9h7NYdun8GkFXkq4RJRZvAAIAAAAAAADHILDp6OTWHFoOX24pkmhvbtYnQ8g2cZAZwwHKZaR7/SF/tatX8I5tEBULWfoqY9WqeLu/WmF2n2mq4RFpbVg6yRZMPdeRbllXqMsG+tSGiiVmdyYT7BP32HlAELpOwtSXbnxNqGomxV7dqfZO2HYAj6qXSLUbnXYmSO7pDiMqT/PUbPSO+1MhcjYSF1UGV11JFihHGNuUyd0VN/bUoW46YWbxzB/zYPk+RUqA1uOfUzVWso8NuDNsE2BWFe4xO1thtJCOQjS9Wo5VA0avOeLO48aMNQ4Awby4aJWW+WzT+qp3v5xqQMwa3m0r8b89CTT2L4LcSD+A5JGE5nwppZyXjFeqgX5W1bY41z6cwjL6U+nW9xhQUzMXDDZ0/nD6bw77+oYQBkes2eexQbUgcl3cjw5OrmdbseOcyo4THzNRfuhZbebMQ/jTEameb/GnFWHoXdmpmR8Md5sEaDXv3X6Qfi2oCw7OXzuCBTHngGf82xw6wQd6ETymES0mZdsvwHTL3HUQBhR6xrAcg4MBPYuGSgVSiAAtresmexfxCDvYIcFf1o6c78w+o3c+w4Cprg6sU+OeF16ouuAjhs3qbX+sgmV9W9tWBPGirQA1WXvePz3LP8SPyjj0BAQ9nnr0tJ59jMtSaRwu6FFnwheVSAyZihggIVTD1pQ+nusFrJkahA==" }, "endpoint": { "endpointId": "Njk6NjI6Qjc6QUU6Mzg6RDQtRGVmYXVsdCBNb2RlbC1OUkNIS0IgLSBMYUNyb3NzZS1UWDE0MVctQmFja3lhcmQtMDAwMDAwOEEtMDAwMC0xMDAwLTgwMDAtMDAyNkJCNzY1Mjkx", "cookie": { "ReportState": "[{\"interface\":\"Alexa.TemperatureSensor\",\"deviceID\":\"TemperatureSensor-Ok\",\"aid\":52,\"iid\":12}]" } }, "payload": {} } };
|
|
206
|
+
|
|
207
|
+
async function sleep(ms) {
|
|
208
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
209
|
+
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
const { alexaMessage, setHomebridge, destroy } = require('/Users/sgracey/Code/homebridge-alexa/src/lib/alexaActions.js');
|
|
2
|
-
|
|
3
|
-
jest.mock("hap-node-client", () => {
|
|
4
|
-
// console.log('Mock - hap-node-client');
|
|
5
|
-
return { HAPNodeJSClient: jest.fn() };
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
const HAPstatusByDeviceID = (deviceID, body, callback) => {
|
|
9
|
-
// console.log('Mock - HAPstatusByDeviceID', deviceID, body, callback);
|
|
10
|
-
switch (deviceID) {
|
|
11
|
-
case "ColorController-1":
|
|
12
|
-
callback(null, { deviceID: "device123", status: "on" });
|
|
13
|
-
break;
|
|
14
|
-
case "TemperatureSensor-Ok":
|
|
15
|
-
callback(null, { "characteristics": [{ "aid": 52, "iid": 12, "value": 2.5 }] });
|
|
16
|
-
break;
|
|
17
|
-
case "TemperatureSensor-NoData":
|
|
18
|
-
callback(null, { "characteristics": [{ "aid": 52, "iid": 12, "status": -70410 }] });
|
|
19
|
-
break;
|
|
20
|
-
default:
|
|
21
|
-
console.log('Missing Mock - HAPstatusByDeviceID', deviceID, body, callback);
|
|
22
|
-
callback(null, { deviceID: "device123", status: "off" });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
setHomebridge({
|
|
27
|
-
HAPstatusByDeviceID: HAPstatusByDeviceID,
|
|
28
|
-
destroy: jest.fn()
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('lib/alexaActions', () => {
|
|
32
|
-
describe('alexaMessage', () => {
|
|
33
|
-
|
|
34
|
-
test('ReportState - ColorController', async () => {
|
|
35
|
-
const message = {
|
|
36
|
-
directive: {
|
|
37
|
-
header: {
|
|
38
|
-
name: 'ReportState'
|
|
39
|
-
},
|
|
40
|
-
endpoint: {
|
|
41
|
-
cookie: {
|
|
42
|
-
ReportState: '[{"deviceID": "ColorController-1", "interface": "Alexa.ColorController", "hue": {"aid": "1", "iid": "1"}, "saturation": {"aid": "1", "iid": "2"}, "brightness": {"aid": "1", "iid": "3"}}]'
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const callback = jest.fn();
|
|
49
|
-
alexaMessage.call({ log: jest.fn() }, message, callback);
|
|
50
|
-
|
|
51
|
-
await sleep(500);
|
|
52
|
-
// Add your assertions here to verify the behavior of the function
|
|
53
|
-
expect(callback).toHaveBeenCalled();
|
|
54
|
-
// expect(callback.mock.calls[0][0].context.properties[0].value).toBe(2.5);
|
|
55
|
-
// ...
|
|
56
|
-
}, 5000);
|
|
57
|
-
|
|
58
|
-
test('ReportState - TemperatureSensor - Ok', async () => {
|
|
59
|
-
const message = { "directive": { "header": { "namespace": "Alexa", "name": "ReportState", "payloadVersion": "3", "messageId": "1cb7b217-3c2d-40e3-ab3d-fb66fb8bca2f", "correlationToken": "AAAAAAAAAAD9h7NYdun8GkFXkq4RJRZvAAIAAAAAAADHILDp6OTWHFoOX24pkmhvbtYnQ8g2cZAZwwHKZaR7/SF/tatX8I5tEBULWfoqY9WqeLu/WmF2n2mq4RFpbVg6yRZMPdeRbllXqMsG+tSGiiVmdyYT7BP32HlAELpOwtSXbnxNqGomxV7dqfZO2HYAj6qXSLUbnXYmSO7pDiMqT/PUbPSO+1MhcjYSF1UGV11JFihHGNuUyd0VN/bUoW46YWbxzB/zYPk+RUqA1uOfUzVWso8NuDNsE2BWFe4xO1thtJCOQjS9Wo5VA0avOeLO48aMNQ4Awby4aJWW+WzT+qp3v5xqQMwa3m0r8b89CTT2L4LcSD+A5JGE5nwppZyXjFeqgX5W1bY41z6cwjL6U+nW9xhQUzMXDDZ0/nD6bw77+oYQBkes2eexQbUgcl3cjw5OrmdbseOcyo4THzNRfuhZbebMQ/jTEameb/GnFWHoXdmpmR8Md5sEaDXv3X6Qfi2oCw7OXzuCBTHngGf82xw6wQd6ETymES0mZdsvwHTL3HUQBhR6xrAcg4MBPYuGSgVSiAAtresmexfxCDvYIcFf1o6c78w+o3c+w4Cprg6sU+OeF16ouuAjhs3qbX+sgmV9W9tWBPGirQA1WXvePz3LP8SPyjj0BAQ9nnr0tJ59jMtSaRwu6FFnwheVSAyZihggIVTD1pQ+nusFrJkahA==" }, "endpoint": { "endpointId": "Njk6NjI6Qjc6QUU6Mzg6RDQtRGVmYXVsdCBNb2RlbC1OUkNIS0IgLSBMYUNyb3NzZS1UWDE0MVctQmFja3lhcmQtMDAwMDAwOEEtMDAwMC0xMDAwLTgwMDAtMDAyNkJCNzY1Mjkx", "cookie": { "ReportState": "[{\"interface\":\"Alexa.TemperatureSensor\",\"deviceID\":\"TemperatureSensor-Ok\",\"aid\":52,\"iid\":12}]" } }, "payload": {} } };
|
|
60
|
-
|
|
61
|
-
const callback = jest.fn();
|
|
62
|
-
alexaMessage.call({ log: jest.fn() }, message, callback);
|
|
63
|
-
|
|
64
|
-
await sleep(500);
|
|
65
|
-
// Add your assertions here to verify the behavior of the function
|
|
66
|
-
// console.log(JSON.stringify(callback.mock.calls[0][1], null, 2));
|
|
67
|
-
expect(callback).toHaveBeenCalled();
|
|
68
|
-
const response = callback.mock.calls[0][1];
|
|
69
|
-
expect(response.context.properties[0].value.value).toBe(2.5);
|
|
70
|
-
expect(response.context.properties[0].value.scale).toBe("CELSIUS");
|
|
71
|
-
// ...
|
|
72
|
-
}, 5000);
|
|
73
|
-
|
|
74
|
-
test('ReportState - TemperatureSensor - No Data', async () => {
|
|
75
|
-
const message = { "directive": { "header": { "namespace": "Alexa", "name": "ReportState", "payloadVersion": "3", "messageId": "1cb7b217-3c2d-40e3-ab3d-fb66fb8bca2f", "correlationToken": "AAAAAAAAAAD9h7NYdun8GkFXkq4RJRZvAAIAAAAAAADHILDp6OTWHFoOX24pkmhvbtYnQ8g2cZAZwwHKZaR7/SF/tatX8I5tEBULWfoqY9WqeLu/WmF2n2mq4RFpbVg6yRZMPdeRbllXqMsG+tSGiiVmdyYT7BP32HlAELpOwtSXbnxNqGomxV7dqfZO2HYAj6qXSLUbnXYmSO7pDiMqT/PUbPSO+1MhcjYSF1UGV11JFihHGNuUyd0VN/bUoW46YWbxzB/zYPk+RUqA1uOfUzVWso8NuDNsE2BWFe4xO1thtJCOQjS9Wo5VA0avOeLO48aMNQ4Awby4aJWW+WzT+qp3v5xqQMwa3m0r8b89CTT2L4LcSD+A5JGE5nwppZyXjFeqgX5W1bY41z6cwjL6U+nW9xhQUzMXDDZ0/nD6bw77+oYQBkes2eexQbUgcl3cjw5OrmdbseOcyo4THzNRfuhZbebMQ/jTEameb/GnFWHoXdmpmR8Md5sEaDXv3X6Qfi2oCw7OXzuCBTHngGf82xw6wQd6ETymES0mZdsvwHTL3HUQBhR6xrAcg4MBPYuGSgVSiAAtresmexfxCDvYIcFf1o6c78w+o3c+w4Cprg6sU+OeF16ouuAjhs3qbX+sgmV9W9tWBPGirQA1WXvePz3LP8SPyjj0BAQ9nnr0tJ59jMtSaRwu6FFnwheVSAyZihggIVTD1pQ+nusFrJkahA==" }, "endpoint": { "endpointId": "Njk6NjI6Qjc6QUU6Mzg6RDQtRGVmYXVsdCBNb2RlbC1OUkNIS0IgLSBMYUNyb3NzZS1UWDE0MVctQmFja3lhcmQtMDAwMDAwOEEtMDAwMC0xMDAwLTgwMDAtMDAyNkJCNzY1Mjkx", "cookie": { "ReportState": "[{\"interface\":\"Alexa.TemperatureSensor\",\"deviceID\":\"TemperatureSensor-NoData\",\"aid\":52,\"iid\":12}]" } }, "payload": {} } };
|
|
76
|
-
|
|
77
|
-
const callback = jest.fn();
|
|
78
|
-
alexaMessage.call({ log: jest.fn() }, message, callback);
|
|
79
|
-
|
|
80
|
-
await sleep(500);
|
|
81
|
-
// Add your assertions here to verify the behavior of the function
|
|
82
|
-
// console.log(JSON.stringify(callback.mock.calls[0][1], null, 2));
|
|
83
|
-
expect(callback).toHaveBeenCalled();
|
|
84
|
-
const response = callback.mock.calls[0][1];
|
|
85
|
-
expect(response.event.header.name).toBe('ErrorResponse');
|
|
86
|
-
expect(response.event.payload.type).toBe('ENDPOINT_UNREACHABLE');
|
|
87
|
-
// ...
|
|
88
|
-
}, 5000);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
test('should handle unknown directive', () => {
|
|
92
|
-
const message = {
|
|
93
|
-
directive: {
|
|
94
|
-
header: {
|
|
95
|
-
name: 'Unknown'
|
|
96
|
-
},
|
|
97
|
-
endpoint: {
|
|
98
|
-
cookie: {
|
|
99
|
-
reportstate: '[{"deviceID": "1", "interface": "Alexa.ColorController", "hue": {"aid": "1", "iid": "1"}, "saturation": {"aid": "1", "iid": "2"}, "brightness": {"aid": "1", "iid": "3"}}]'
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const callback = jest.fn();
|
|
106
|
-
|
|
107
|
-
alexaMessage.call({ log: jest.fn() }, message, callback);
|
|
108
|
-
|
|
109
|
-
// Add your assertions here to verify the behavior of the function
|
|
110
|
-
expect(callback).toHaveBeenCalled();
|
|
111
|
-
// ...
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
afterAll(() => {
|
|
115
|
-
destroy();
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
async function sleep(ms) {
|
|
120
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
121
|
-
}
|