-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8be775
commit 78a0240
Showing
2 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
server/test/lib/scene/actions/scene.action.sendZigbee2MqttMessage.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const { fake, assert } = require('sinon'); | ||
const EventEmitter = require('events'); | ||
|
||
const { ACTIONS } = require('../../../../utils/constants'); | ||
const { executeActions } = require('../../../../lib/scene/scene.executeActions'); | ||
|
||
const StateManager = require('../../../../lib/state'); | ||
|
||
const event = new EventEmitter(); | ||
|
||
describe('scene.send-zigbee2mqtt-message', () => { | ||
it('should send message with value injected from device get-value', async () => { | ||
const stateManager = new StateManager(event); | ||
stateManager.setState('deviceFeature', 'my-device-feature', { | ||
category: 'light', | ||
type: 'binary', | ||
last_value: 15, | ||
}); | ||
const zigbee2MqttService = { | ||
device: { | ||
publish: fake.resolves(null), | ||
}, | ||
}; | ||
const service = { | ||
getService: fake.returns(zigbee2MqttService), | ||
}; | ||
const scope = {}; | ||
await executeActions( | ||
{ stateManager, event, service }, | ||
[ | ||
[ | ||
{ | ||
type: ACTIONS.DEVICE.GET_VALUE, | ||
device_feature: 'my-device-feature', | ||
}, | ||
], | ||
[ | ||
{ | ||
type: ACTIONS.ZIGBEE2MQTT.SEND, | ||
topic: '/my/mqtt/topic', | ||
message: 'Temperature in the living room is {{0.0.last_value}} °C.', | ||
}, | ||
], | ||
], | ||
scope, | ||
); | ||
assert.calledWith(zigbee2MqttService.device.publish, '/my/mqtt/topic', 'Temperature in the living room is 15 °C.'); | ||
}); | ||
it('should send message with value injected from http-request', async () => { | ||
const stateManager = new StateManager(event); | ||
const http = { | ||
request: fake.resolves({ result: [15], error: null }), | ||
}; | ||
const zigbee2MqttService = { | ||
device: { | ||
publish: fake.resolves(null), | ||
}, | ||
}; | ||
const service = { | ||
getService: fake.returns(zigbee2MqttService), | ||
}; | ||
const scope = {}; | ||
await executeActions( | ||
{ stateManager, event, service, http }, | ||
[ | ||
[ | ||
{ | ||
type: ACTIONS.HTTP.REQUEST, | ||
method: 'post', | ||
url: 'http://test.test', | ||
body: '{"toto":"toto"}', | ||
headers: [], | ||
}, | ||
], | ||
[ | ||
{ | ||
type: ACTIONS.ZIGBEE2MQTT.SEND, | ||
topic: '/my/mqtt/topic', | ||
message: 'Temperature in the living room is {{0.0.result.[0]}} °C.', | ||
}, | ||
], | ||
], | ||
scope, | ||
); | ||
assert.calledWith(zigbee2MqttService.device.publish, '/my/mqtt/topic', 'Temperature in the living room is 15 °C.'); | ||
}); | ||
}); |