forked from GladysAssistant/Gladys
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GladysAssistant#540: In MQTT service UI, display broker configura…
…tion errors (By Atrovato) (GladysAssistant#667) * fix GladysAssistant#540 : handle mqtt connect error * Improve MQTT service UX * Add tests to mqtt connection error/success Co-authored-by: Alexandre Trovato <1839717+atrovato@users.noreply.github.com>
- Loading branch information
1 parent
d23dac8
commit ce9baab
Showing
8 changed files
with
81 additions
and
10 deletions.
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
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
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
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
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
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
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
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,60 @@ | ||
const sinon = require('sinon'); | ||
|
||
const { assert, fake } = sinon; | ||
const { EVENTS, WEBSOCKET_MESSAGE_TYPES } = require('../../../../utils/constants'); | ||
const { MockedMqttClient } = require('../mocks.test'); | ||
|
||
const MqttHandler = require('../../../../services/mqtt/lib'); | ||
|
||
describe('mqttHandler.connect', () => { | ||
it('should connect and receive success', async () => { | ||
const gladys = { | ||
variable: { | ||
getValue: fake.resolves('result'), | ||
}, | ||
event: { | ||
emit: fake.returns(null), | ||
}, | ||
}; | ||
const mqttHandler = new MqttHandler(gladys, MockedMqttClient, 'faea9c35-759a-44d5-bcc9-2af1de37b8b4'); | ||
await mqttHandler.connect(); | ||
mqttHandler.mqttClient.emit('connect'); | ||
assert.calledWith(gladys.event.emit, EVENTS.WEBSOCKET.SEND_ALL, { | ||
type: WEBSOCKET_MESSAGE_TYPES.MQTT.CONNECTED, | ||
}); | ||
}); | ||
it('should connect and receive error', async () => { | ||
const gladys = { | ||
variable: { | ||
getValue: fake.resolves('result'), | ||
}, | ||
event: { | ||
emit: fake.returns(null), | ||
}, | ||
}; | ||
const mqttHandler = new MqttHandler(gladys, MockedMqttClient, 'faea9c35-759a-44d5-bcc9-2af1de37b8b4'); | ||
await mqttHandler.connect(); | ||
mqttHandler.mqttClient.emit('error', { test: 'test' }); | ||
assert.calledWith(gladys.event.emit, EVENTS.WEBSOCKET.SEND_ALL, { | ||
type: WEBSOCKET_MESSAGE_TYPES.MQTT.ERROR, | ||
payload: { test: 'test' }, | ||
}); | ||
}); | ||
it('should connect and receive offline', async () => { | ||
const gladys = { | ||
variable: { | ||
getValue: fake.resolves('result'), | ||
}, | ||
event: { | ||
emit: fake.returns(null), | ||
}, | ||
}; | ||
const mqttHandler = new MqttHandler(gladys, MockedMqttClient, 'faea9c35-759a-44d5-bcc9-2af1de37b8b4'); | ||
await mqttHandler.connect(); | ||
mqttHandler.mqttClient.emit('offline'); | ||
assert.calledWith(gladys.event.emit, EVENTS.WEBSOCKET.SEND_ALL, { | ||
type: WEBSOCKET_MESSAGE_TYPES.MQTT.ERROR, | ||
payload: 'DISCONNECTED', | ||
}); | ||
}); | ||
}); |